JSON-RPC 2.0 MCP server

Type-safe JSON-RPC 2.0 server implementation in Scala 3 that enables structured communication between assistants and backend services with comprehensive error handling.
Back to servers
Setup instructions
Provider
windymelt
Release date
Apr 01, 2025
Stats
35 stars

This MCP-scala server implements the Model Context Protocol, allowing you to define and execute custom tools through a standardized interface.

Getting Started

Building the Server

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.

Configuration

Client Setup

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.

Available Tools

The MCP-scala server comes with several pre-built tools:

  • randomNumber - Generates a random number between min and max values
  • iota - Creates a sequence of numbers from min to max
  • sum - Calculates the sum of a sequence of numbers

Creating Custom Tools

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.

How to install this MCP server

For Claude Code

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.

For Cursor

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.

Adding an MCP server to Cursor globally

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"
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later