This MCP-scala server implements the Model Context Protocol, allowing you to define and execute custom tools through a standardized interface.
To build the MCP server, use the SBT build tool:
sbt example/fastLinkJS
This command compiles the server to JavaScript, making it ready for use with any MCP client.
After building the server, you need to configure your MCP client to recognize it. Below is an example configuration for the Cline client:
{
"mcpServers": {
"mcpscala": {
"disabled": false,
"timeout": 30,
"command": "sh",
"args": ["/path/to/run.sh"],
"transportType": "stdio"
}
}
}
Make sure to update the path to your run script accordingly.
The MCP-scala server comes with several pre-built tools:
min
and max
valuesmin
to max
You can implement your own tools by following the pattern shown below:
//> using scala 3
//> using toolkit typelevel:default
//> using dep dev.capslock::mcpscala:0.1.0
package dev.capslock.mcpscala
import cats.effect.IO
import cats.effect.IOApp
import dev.capslock.mcpscala.transport.StdioServer
import dev.capslock.mcpscala.mcp.ContentPart
import sttp.tapir.Schema.annotations.description
// Define your input schema with optional descriptions
case class RandomNumberInput(
@description("Minimum value (inclusive)") min: Int,
@description("Maximum value (exclusive)") max: Int
) derives io.circe.Decoder,
sttp.tapir.Schema
// Implement your tool logic
def randomNumber(input: RandomNumberInput): IO[Seq[ContentPart]] = IO {
val random = scala.util.Random.between(input.min, input.max)
Seq(ContentPart.TextContentPart(random.toString))
}
// Create an entry point that registers your tools
object StdioMain extends McpIOApp(
name = "random-number",
header = "Generate a random number",
):
val handlers = Handler.methodHandlers(
Map(
"randomNumber" -> server.Tool(randomNumber),
)
)
The server automatically derives JSON schemas from your case classes and handles the communication protocol details for you.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mcpscala" '{"disabled":false,"timeout":30,"command":"sh","args":["/path/to/run.sh"],"transportType":"stdio"}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"mcpscala": {
"disabled": false,
"timeout": 30,
"command": "sh",
"args": [
"/path/to/run.sh"
],
"transportType": "stdio"
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"mcpscala": {
"disabled": false,
"timeout": 30,
"command": "sh",
"args": [
"/path/to/run.sh"
],
"transportType": "stdio"
}
}
}
3. Restart Claude Desktop for the changes to take effect