Sakura MCP is a Scala implementation of the Model Context Protocol that enables interoperable communication between AI models and services. This library provides developers with a fluent API for constructing and sending model context requests, while handling the serialization and deserialization of JSON data. The library supports various input and output types including text and images, and offers configuration options for API keys, base URLs, and timeouts. With Sakura MCP, developers can easily integrate AI model capabilities into their Scala applications with minimal boilerplate code.
Sakura MCP is a Scala library that implements the Model Context Protocol, allowing for standardized communication between AI models and services. This library makes it easy to integrate AI capabilities into your Scala applications.
To use Sakura MCP in your Scala project, add the following dependency to your build.sbt
file:
libraryDependencies += "com.github.mullerhai" %% "mcp" % "0.1.0" // Replace with latest version
Here's a simple example of how to use the Sakura MCP library:
import com.github.mullerhai.mcp._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.duration._
// Configure client with your API key
val apiKey = "YOUR_API_KEY"
val client = new MCPClient(apiKey)
// Build a context for your request
val context = ModelContext(
model = "llama2",
input = TextInput("What is the capital of France?"),
parameters = List(MaxTokens(50))
)
// Send the request
val future = client.send(context)
// Handle the response
val response = Await.result(future, 5.seconds)
println(response)
The MCPClient
can be configured with the following options:
apiKey
: (Required) Your MCP API keybaseUrl
: (Optional) The base URL of the MCP API (defaults to "https://api.modelcontext.com/v1")timeout
: (Optional) Request timeout in seconds (defaults to 10)Example with custom configuration:
val client = new MCPClient(
apiKey = "YOUR_API_KEY",
baseUrl = "https://your-custom-api.com",
timeout = 15
)
Sakura MCP supports the following input and output types:
Input Types:
TextInput
: For text-based inputImageInput
: For image input (base64 encoded)Output Types:
TextOutput
: For text-based outputImageOutput
: For image output (base64 encoded)The send
method returns a Future[Output]
. You can handle errors using standard Scala error handling mechanisms:
try {
val future = client.send(context)
val response = Await.result(future, 5.seconds)
println(response)
} catch {
case e: Exception => println(s"Error: ${e.getMessage}")
}
For more complex scenarios, you can build more sophisticated contexts with multiple parameters:
val context = ModelContext(
model = "gpt-4",
input = TextInput("Generate a creative story about a robot learning to paint"),
parameters = List(
MaxTokens(500),
Temperature(0.8),
TopP(0.95)
)
)