FastMCP-Scalaのロゴ

FastMCP-Scala

組織
TJC-LP

A quick and easy way to deploy MCP servers using Scala

公開者TJC-LP
リポジトリfast-mcp-scala
言語Scala
フォーク
2
スター
24
利用可能なツール
0
通信方式stdio, streamable-http
カテゴリ
ライセンスMIT
リンク
  • ツールをAIワークフローに接続

    FastMCP-Scalaは、対応するAIクライアントやAIエージェントから利用できるMCP機能を提供します。

  • 0個の利用可能なツール

    呼び出し可能なアクションを以下で確認できます。サーバーから提供されている場合は、名前や説明も表示されます。

  • コピーして使える設定

    セットアップ用の設定例を使って、お好みのMCPクライアントにこのサーバーを設定できます。

  • オープンソースの注目度

    リンク先のリポジトリには24件のスターと2件のフォークがあります。

fast-mcp-scala

Maven Central CI Conformance Native Image License: MIT

Scala 3 for MCP: annotation-driven and typed-contract APIs on the JVM, Scala.js/Bun, and Scala Native.

fast-mcp-scala is a developer-friendly library for building Model Context Protocol servers. Extend one trait, declare your tools, done:

scala
object HelloWorld extends McpServerApp[Stdio, HelloWorld.type]:
  @Tool(name = Some("add"))
  def add(@Param("a") a: Int, @Param("b") b: Int): Int = a + b

Two registration paths, @Tool-style annotations and typed McpTool contracts, converge on the same backend. Built on ZIO 2 and zio-json, with JSON Schemas derived directly by Scala 3 macros. The whole MCP protocol layer (JSON-RPC, wire types, router, transports) is native Scala 3 in shared/; there is no vendored SDK. It targets MCP 2026-07-28 and keeps a compatibility adapter for earlier protocol revisions.

Installation

scala
// sbt — JVM
libraryDependencies += "com.tjclp" %% "fast-mcp-scala" % "1.0.1"

// sbt — Scala.js (Bun-first) or Scala Native (stdio only, experimental); %%% picks the platform artifact
libraryDependencies += "com.tjclp" %%% "fast-mcp-scala" % "1.0.1"

//> using dep com.tjclp::fast-mcp-scala:1.0.1    // scala-cli, JVM
//> using dep com.tjclp::fast-mcp-scala::1.0.1   // scala-cli, Scala.js or Native (with `//> using platform ...`)

Built against Scala 3.9.0 LTS: consuming 1.0.0 requires Scala 3.9.0 or newer (it emits TASTy 28.9, which 3.8 and older compilers cannot read; the RC3 prerelease, built with Scala 3.8.3, is the last release a Scala 3.8 project can use). 1.0.0 is not compiled with -experimental, so consumers no longer need the flag (the release candidates required it on every registration path; TJC-2335). JVM: JDK 17+ (CI tests the LTS releases 17, 21, and 25). Scala.js: sjs1_3, runs on Bun (first-class) and, for stdio, on Node 18+ (verified with Node 18 and 26 in the 1.0.0 dogfood, not yet in CI; the HTTP listener is Bun.serve-only, and bearer task ids come from globalThis.crypto, which Node 18 exposes only behind --experimental-global-webcrypto); Scala 3.9 output needs a Scala.js 1.22+ linker (Mill: mill-bun 0.3.x with an explicit scalaJSVersion; scala-cli: --js-version 1.22.0). Scala Native: native0.5_3, stdio only, experimental. Platform details and quickstarts: docs/platforms.md.

Quickstart

A single-file server with one tool; the same code lives in HelloWorld.scala:

scala
//> using scala 3.9.0
//> using dep com.tjclp::fast-mcp-scala:1.0.1

import com.tjclp.fastmcp.{*, given}

object HelloWorld extends McpServerApp[Stdio, HelloWorld.type]:

  @Tool(name = Some("add"), description = Some("Add two numbers"), readOnlyHint = Some(true))
  def add(@Param("First operand") a: Int, @Param("Second operand") b: Int): Int = a + b

No import zio.*, no override def run, no ZIO.succeed(...). The McpServerApp[T, Self] trait handles server construction, annotation scanning, and transport lifecycle; the transport is a phantom type parameter (Stdio / Http) that selects the runner at compile time.

Exercise it through the MCP Inspector:

bash
npx @modelcontextprotocol/inspector scala-cli scripts/quickstart.sc

The first run downloads the compiler and dependencies (about 60 MB) and compiles the script, which can exceed the Inspector's 15 s connect timeout (it then reports only Connection closed). Run scala-cli compile scripts/quickstart.sc once beforehand, or pass --connect-timeout <ms> to the Inspector.

Choosing a registration path

Annotations (@Tool + scanAnnotations)Typed contracts (McpTool)
StyleMethods on an object, discovered by macroFirst-class vals
SchemaDerived from method signature & @ParamDerived from case-class fields & @Param
TestingCall the method directlyInvoke .handler on the value
ComposabilityWhatever methods the object exposesCollect into lists, generate from config
Best forQuick servers, prototypes, single-module appsLibraries, cross-module sharing, production codebases

Both work on every platform and coexist on the same server: override tools / prompts / staticResources / templateResources on your McpServerApp to mount typed contracts alongside annotated methods.

scala
case class AddArgs(a: Int, b: Int)
case class AddResult(sum: Int)

object MyServer extends McpServerApp[Stdio, MyServer.type]:
  @Tool(name = Some("ping")) def ping(): String = "pong"

  override val tools = List(
    McpTool[AddArgs, AddResult](name = "add") { args =>
      AddResult(args.a + args.b)            // plain value — auto-lifted
    }
  )

A typed tool's In is a case class (its schema must be a JSON object, as MCP arguments always are); a tool with no arguments takes an empty one — case class NoArgs() — since McpTool[Unit, _] has no decoder. Handler lambdas return plain values, ZIO, Either[Throwable, _], or scala.util.Try; the ToHandlerEffect[F[_], R] typeclass picks the right lift (R is the ZIO environment — Any for the plain builders), and you can bring your own given for other effect systems by implementing ToHandlerEffect[F, Any] for your effect type F. See AnnotatedServer.scala for the annotation path and ContractServer.scala for typed contracts.

Tools and @Param metadata

Every tool parameter can carry metadata that flows into the derived JSON Schema:

scala
@Tool(name = Some("search"), description = Some("Search with optional filters"))
def search(
    @Param(description = "Search query", examples = List("scala", "mcp"))
    query: String,
    @Param(description = "Maximum results", examples = List("10", "25"), required = false)
    limit: Option[Int],
    @Param(
      description = "Sort order",
      schema = Some("""{"type": "string", "enum": ["relevance", "date"]}""")
    )
    sortBy: String
): String = ???
  • description populates the schema's description field
  • examples populates the JSON Schema examples array (clients can show suggestions)
  • required = false, combined with Option[...] or a default value, marks the field optional; a bare Option[...] parameter is optional without it, but a default value alone does not remove the field from required — the default is applied when the argument is omitted, so write required = false to advertise it as optional
  • schema is a raw JSON Schema fragment that overrides the derived schema entirely — repeat the description inside the fragment, since the derived property (description and examples included) is replaced wholesale

An annotated method's result is sent as TextContent(result.toString) unless it is a String, a Content, a List[Content], an Array[Byte] (or a ZIO of one of those): a Some(1), a case class or a Map arrives as Scala's toString text, not JSON. Return a String/Content, or use a typed McpTool (with .withOutputSchema for structuredContent) when clients need JSON.

Overloading is fine: only the annotated overload is registered, and its schema and handler come from that exact declaration; two annotated overloads must register distinct names — duplicate names or resource URI patterns within one object are a compile-time error. Annotation arguments such as name, description and the hints must be literals (Some("..."), Option("..."), None, or a final val constant); anything else is a compile-time error.

An annotated method has exactly one parameter list (no currying, no using clauses), no type parameters, and at most 22 parameters, and only members declared directly on the scanned object are registered (private/protected included — visibility does not gate exposure, so annotate only what you mean to publish). An annotated inherited member or val, like any other unsupported shape, is a compile-time error naming it and the fix; an annotated method inside a nested object is reported as well (an error when the scanned object declares nothing of its own, otherwise a warning, since the nested object may be scanned separately).

Enums, nested case classes, Option, collections, and java.time values derive with no user-supplied givens; custom wire shapes go through McpInputCodec. See docs/custom-types.md.

Tool hints

MCP Tool Annotations tell the client how a tool behaves. Set them on @Tool:

HintMeaning
titleHuman-readable display name (distinct from the wire-level name)
readOnlyHintThe tool only reads state; safe to call without confirmation
destructiveHintThe tool may irreversibly modify state; clients should confirm
idempotentHintRepeated calls with the same args have the effect of one call
openWorldHintThe tool reaches outside the local process (network, filesystem, APIs)
returnDirectReturn the result directly to the user, skipping LLM post-processing

TaskManagerServer.scala applies hints across a realistic tool set.

Resources (static and templated)

Static resources have a fixed URI and no parameters:

scala
@Resource(uri = "static://welcome", description = Some("A welcome message"))
def welcome(): String = "Welcome!"

Templated resources use {placeholders} in the URI, matched against method parameter names:

scala
@Resource(
  uri = "users://{userId}/profile",
  description = Some("User profile as JSON"),
  mimeType = Some("application/json")
)
def userProfile(@Param("The user id") userId: String): String =
  s"""{"userId":"$userId"}"""

Templates are listed through resources/templates/list only when exposeTemplatesEndpoint is set (resources/list never lists templates; with the default false the templates endpoint answers an empty page and clients derive templates from {} URIs; resources/read on a matching URI works either way). AnnotatedServer.scala turns it on:

scala
override def settings = McpServerSettings(exposeTemplatesEndpoint = true)

A placeholder matches a non-empty run of characters within one path segment (never /); literal text is matched verbatim (not as a regex); placeholders in the same segment must be separated by literal text (a template such as x://{a}{b} is rejected at registration, so the server fails to start). Client URIs longer than limits.maxUriChars (8192) are rejected with -32602.

Prompts

Return a List[Message]; fast-mcp-scala handles the MCP framing:

scala
@Prompt(name = Some("greeting"), description = Some("Personalized greeting"))
def greeting(
    @Param("Name of the person") name: String,
    @Param("Optional title", required = false) title: String = ""
): List[Message] =
  List(Message(Role.User, TextContent(s"Generate a warm greeting for $title $name.")))

A prompt that returns a single String is automatically wrapped into a User message.

Context (McpContext)

Add a parameter named exactly ctx of type McpContext to a @Tool method to read the client's declared info and capabilities, request metadata, and to send progress or logging (the parameter is recognised by its name and is not part of the tool's schema; @Prompt and @Resource methods do not take a context parameter):

scala
@Tool(name = Some("echo"), description = Some("Echo client and request context"))
def echo(
    @Param(description = "Optional note to include", required = false) note: Option[String],
    ctx: McpContext
): String =
  val clientName = ctx.getClientInfo.map(_.name).getOrElse("Unknown Client")
  s"Hello from $clientName${note.fold("")(n => s": $n")}"

Client-visible logging goes through the context too: ctx.sendLogMessage(level, data) returns a ZIO (so the handler returns one), and LoggingLevel (in com.tjclp.fastmcp.core) is root-exported since 1.0.0 — the release candidates needed it imported by name, which still works:

scala
import zio.*
import zio.json.ast.Json
import com.tjclp.fastmcp.core.LoggingLevel   // optional since 1.0.0 (root-exported); the release candidates need it

@Tool(name = Some("echo_logged"), description = Some("Echo the note and log it"))
def echoLogged(@Param("Note to echo") note: String, ctx: McpContext): ZIO[Any, Throwable, String] =
  ctx.sendLogMessage(LoggingLevel.Info, Json.Str(s"echo: $note")).as(note)

Typed contracts use the builder's .contextual — McpTool[In, Out](name = "echo").contextual { (in, ctx) => ... } — whose handler receives (In, Option[McpContext]). Runnable demo: ContextEchoServer.scala.

Transports

Transport is a phantom type parameter on McpServerApp[T, Self]: Stdio or Http.

stdio (for Claude Desktop, MCP Inspector)

scala
object MyServer extends McpServerApp[Stdio, MyServer.type]:
  @Tool(...) def hello(name: String): String = s"Hello, $name!"

HTTP (for remote clients, load balancers, test harnesses)

scala
object MyHttpServer extends McpServerApp[Http, MyHttpServer.type]:
  override def settings = McpServerSettings(port = 8090)

  @Tool(...) def hello(name: String): String = s"Hello, $name!"

For MCP 2026-07-28, runHttp() accepts one stateless JSON-RPC message per POST /mcp, answering with JSON or a request-scoped SSE stream. Older clients are served by a legacy initialize/session adapter that is on by default.

SettingDefaultDescription
host127.0.0.1Bind address; set "0.0.0.0" for containers or external exposure
port8000Listen port
statelessfalseDisable the legacy session adapter; modern requests are always stateless

All settings, required request headers, error-code mapping, the legacy adapter, and lower-level construction without the sugar trait: docs/transports.md.

Native image (GraalVM)

Stdio servers compile to self-contained GraalVM binaries with zero hand-written reachability metadata (about 35 MB, instant startup, no JVM in the container): registration and schema derivation are compile-time macros, and the transport-seam split keeps zio-http/netty out of stdio-only images — exclude dev.zio:zio-http_3 from the dependency (netty arrives only through zio-http, so that single exclusion sheds both). HTTP servers compile too and pass the official conformance suite as a native binary in CI. Recipes, flags, and the metadata audit loop: docs/native-image.md.

Platforms

One core, three targets. The protocol layer is shared; each platform contributes only a transport backend.

JVMScala.js / BunScala Native (experimental)
Annotations, typed contracts, McpServerApp✅✅✅
Stdio✅✅✅ (LLVM binary)
Streamable HTTP, MCP 2026-07-28✅ ZIO HTTP✅ Bun.serve✗ by design¹
Legacy HTTP session adapter✅✅✗ by design¹
Tasks extension✅✅✅ (stdio)
Standalone binaryGraalVM native image—LLVM via Scala Native

¹ zio-http has no Scala Native artifacts, so McpServerApp[Http] does not compile there; a socket-based backend is in progress (#81).

The official MCP conformance suite runs in CI against the JVM and Bun servers and against the GraalVM native binary, with empty expected-failure baselines. Full parity matrix, Bun and Scala Native quickstarts: docs/platforms.md; coverage details: docs/spec-coverage.md.

Documentation

Claude Desktop integration

Add to claude_desktop_config.json:

json
{
  "mcpServers": {
    "fast-mcp-scala-example": {
      "command": "scala-cli",
      "args": [
        "-e",
        "//> using scala 3.9.0",
        "-e",
        "//> using dep com.tjclp::fast-mcp-scala:1.0.1",
        "--main-class",
        "com.tjclp.fastmcp.examples.AnnotatedServer"
      ]
    }
  }
}

fast-mcp-scala example servers are for demo purposes only. They don't do anything useful, but they make it easy to see MCP in action.

License

MIT

インストール

TypingMind
{
  "mcpServers": {
    "fast-mcp-scala": {
      "command": "scala-cli",
      "args": [
        "-e",
        "//> using dep com.tjclp::fast-mcp-scala:0.1.1",
        "--main-class",
        "com.tjclp.fastmcp.examples.AnnotatedServer"
      ]
    }
  }
}

FastMCP-ScalaのMCPを複数のAIモデルで活用

TypingMindはワークスペース単位でMCPツールに接続します。そのため、一度FastMCP-Scalaに接続すれば、モデルごとに個別に設定することなく、TypingMind内のさまざまなAIモデルで利用できます。 お使いのデバイス上でMCPをローカル実行することも、リモートMCPサーバーのURLに接続することもできます。

方法1:ローカルコネクタを使用

MCPサーバーが、お使いのコンピューター上のローカルファイル、アプリ、非公開リソースにアクセスする必要がある場合は、この方法を使います。

1

MCP設定を開く

TypingMindで「設定」、「詳細設定」、「MCP」の順に進み、「コネクタを設定」を選択してください。

  1. ブラウザでTypingMindを開いてください。
  2. 設定アイコンをクリックしてください。
  3. 「詳細設定」に移動してください。
  4. 「MCP」セクションを開いてください。
  5. 「コネクタを設定」をクリックし、「このデバイス」を選択してください。
「このデバイス」が選択されたTypingMindのMCPコネクタ設定画面
2

コネクタのコマンドを実行

「このデバイス」を選択し、TypingMindからコマンドをコピーしてターミナルで実行してください。MCPの使用中は、プロセスを実行したままにしてください。

  1. TypingMindに表示されるセットアップコマンドをコピーしてください。
  2. macOSではターミナルを、WindowsではWindows Terminalを開いてください。
  3. コマンドを貼り付けて実行してください。
  4. ターミナルで続行の確認を求められた場合は、パッケージのインストールを承認してください。
  5. MCPツールの使用中は、ターミナルウィンドウを開いたまま、プロセスの実行を継続してください。
3

FastMCP-Scalaをサーバーとして追加

コネクタのステータスが「準備完了」になったら、「サーバーを編集」をクリックし、MCPサーバーの設定を貼り付けてください。

  1. コネクタのステータスが「準備完了」になるまでお待ちください。
  2. 「サーバーを編集」をクリックしてください。
  3. FastMCP-ScalaのMCPサーバー設定を貼り付けてください。
  4. サーバー一覧を保存してください。
  5. コネクタが引き続き使用可能か確認するには、更新してください。
稼働中のサーバーと「サーバーを編集」ボタンが表示されたTypingMindのMCP設定画面
{
  "mcpServers": {
    "fast-mcp-scala": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

複数のモデルで同じ接続を使用

サーバー一覧を保存し、「プラグイン」を開いてFastMCP-ScalaのMCPツールを有効にしてください。その後、TypingMindで対応するAIモデルを選択し、チャットでツールを使うか、AIエージェントに割り当ててください。

  1. TypingMindの「プラグイン」ページを開いてください。
  2. FastMCP-ScalaのMCPツールを有効にしてください。
  3. チャットを開始し、使用するAIモデルを選択してください。
  4. MCPツールをチャットで使うか、AIエージェントに割り当ててください。
  5. MCPに再接続することなく、必要に応じて別のAIモデルに切り替えられます。
選択したAIモデルと有効なMCPツールを使用したTypingMindのチャット
FastMCP-Scalaを使ってこのタスクを手伝ってもらえますか?
FastMCP-Scala
はい、読みました。
FastMCP-Scalaで調べた結果をお伝えします。

方法2:MCPサーバーのURLを追加

FastMCP-Scalaがすでにリモートでホストされている場合や、チームの複数のユーザーで1つのコネクタを共有したい場合は、この方法を使います。

1

MCPコネクタを開く

TypingMindで「プラグイン」に移動し、「MCPコネクタ」を開いて「URLを追加」を選択してください。

  1. ブラウザでTypingMindを開いてください。
  2. 「プラグイン」に移動してください。
  3. 「MCPコネクタ」を開いてください。
  4. 「URLを追加」をクリックします。
TypingMindの「カスタムMCPサーバーURLを追加」フォーム
2

サーバーURLを貼り付け

「サーバーURL」欄にプロバイダーから提供されたMCPサーバーのURLを入力してください。サーバーで必要とされる場合は、接続名、説明、アイコン、カスタムHTTPヘッダー、OAuthクライアント設定を追加してください。

  1. 「サーバーURL」欄にプロバイダーから提供されたMCPサーバーのURLを貼り付けてください。
  2. FastMCP-Scalaの接続名を入力してください。
  3. 接続を識別しやすくするには、説明とアイコンを追加してください。
  4. サーバーで認証が必要な場合は、カスタムHTTPヘッダーまたはOAuthクライアントの詳細情報を追加してください。
3

接続を作成

「接続を作成」をクリックし、プラグイン一覧に戻って、新しいMCP接続が有効になっていることを確認してください。

  1. 「接続を作成」をクリックします。
  2. MCPコネクタの一覧に戻ってください。
  3. FastMCP-Scalaの接続が「有効」と表示されていることを確認してください。
  4. 接続がすぐに表示されない場合は、プラグイン一覧を更新してください。
4

再接続せずにモデルを切り替え

お好みのモデルでチャットを開始し、「プラグイン」でFastMCP-Scalaのツールを有効にしてください。必要に応じて別のモデルに切り替えられます。MCP接続は、TypingMindのワークスペースで引き続き利用できます。

  1. TypingMindで新しいチャットを開始してください。
  2. 使用するAIモデルを選択してください。
  3. 「プラグイン」でFastMCP-Scalaのツールを有効にしてください。
  4. 必要に応じて、ツールを使うようモデルに依頼してください。
  5. 別のAIモデルに切り替えて、同じMCP接続を再利用してください。
選択したAIモデルと有効なMCPツールを使用したTypingMindのチャット
FastMCP-Scalaを使ってこのタスクを手伝ってもらえますか?
FastMCP-Scala
はい、読みました。
FastMCP-Scalaで調べた結果をお伝えします。

よくある質問

FastMCP-Scala MCPサーバーは何に使いますか?

FastMCP-Scalaは、対応するAIクライアントを外部ツールやコンテキストに接続するためのMCPサーバーです。TypingMindでは、このMCPサーバーを一度追加するだけで、AIワークスペース内でそのツールを利用できるようになります。

TypingMindでFastMCP-Scala MCPを複数のAIモデルと併用できますか?

はい。TypingMindはワークスペース単位でMCPツールに接続するため、モデルごとにMCPサーバーを設定する必要はありません。Claude、ChatGPT、Geminiや、TypingMindで設定したその他のAIモデルでFastMCP-Scalaを利用できます。

TypingMindでFastMCP-Scala MCPを使うメリットは何ですか?

TypingMindは、複数のAIモデル、プロンプト、プラグイン、AIエージェント、APIキー、MCPツールを1つのワークスペースにまとめられる、LLMチャット向けの優れたフロントエンドです。FastMCP-Scalaを接続すると、TypingMindでチャットのワークフローを整理しながら、お好みのモデルでそのMCPツールを利用できます。

FastMCP-Scala MCPをTypingMindに接続するにはどうすればよいですか?

FastMCP-Scalaは、ローカルMCPコネクタを使うか、リモートMCPサーバーのURLを追加することでTypingMindに接続できます。サーバーがデバイス上のファイル、アプリ、プライベートリソースにアクセスする必要がある場合はローカルコネクタを、MCPサーバーがリモートでホストされている場合はサーバーURLを使用してください。

TypingMindでFastMCP-Scala MCPのどのようなツールを利用できますか?

FastMCP-ScalaはMCP機能を提供しています。TypingMindのプラグインページで有効にすると、チャットで使用したり、AIエージェントに割り当てたりできます。

FastMCP-Scala MCPを使うには、APIキーをTypingMindと共有する必要がありますか?

いいえ。TypingMindはローカルファーストの設計で、モデルプロバイダー、APIキー、プロンプト、MCP設定をご自身で管理できます。FastMCP-Scalaで認証が必要な場合は、接続の作成時に、そのMCPサーバーに必要なヘッダー、OAuth設定、またはローカル設定を追加してください。

関連するMCPサーバー

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇