Julia server and client utilities for the Model Context Protocol (MCP).
The package supports the stateful MCP 2025-11-25 protocol and the stateless
MCP 2026-07-28 protocol over Streamable HTTP. Clients default to
2025-11-25 for compatibility. The package includes discovery manifests,
OAuth-protected resources, tools, prompts, resources, completions, logging,
multi-round-trip results, subscriptions, and custom tool headers. It also
ships first-class support for MCP Apps (SEP-1865) —
interactive HTML widgets rendered inline by hosts like Cursor and Claude; see
MCP-App-playbook.md for the end-to-end guide.
This JuliaServices package is currently unregistered. The General registry has
a separate package with the same name, so Pkg.add("ModelContextProtocol")
does not install this checkout.
Use a URL or local development checkout instead:
using Pkg
Pkg.develop(url="https://github.com/JuliaServices/ModelContextProtocol.jl")using ModelContextProtocol
server = MCPServer(MCPServerConfig(name="Calculator", version="0.1.0"))
register_tool!(
server;
name="add",
description="Add numbers.",
input_schema=Dict(
"type" => "object",
"properties" => Dict(
"numbers" => Dict("type" => "array", "items" => Dict("type" => "number")),
),
"required" => ["numbers"],
),
handler=function (_context, args)
total = sum(Float64.(args["numbers"]))
return Dict(
"content" => [Dict("type" => "text", "text" => string(total))],
"structuredContent" => Dict("sum" => total),
)
end,
)
http_server = serve_mcp_http(server; host="127.0.0.1", port=3010)
wait(http_server.http)The package also provides a specialized, tools-only server with a concrete
request graph for JuliaC --trim=safe builds. Its API is namespaced and is not
exported. See the
trim-safe static server guide
for the example and support limits.
using ModelContextProtocol
discovery = discover_server("http://127.0.0.1:3010")
client = prepare_manual_client(discovery)
initialize_client!(client)
result = call_tool(client, "add"; arguments=Dict("numbers" => [1, 3, 4]))
terminate_session!(client)Use the stateless protocol when the server supports MCP 2026-07-28:
client = prepare_manual_client(
discovery;
config=MCPClientConfig(
protocol_version=ModelContextProtocol.PROTOCOL_VERSION_2026_07_28,
),
capabilities=Dict("elicitation" => Dict()),
)
initialize_client!(client) # calls server/discoverSee the MCP 2026-07-28 guide for capability checks, multi-round-trip results, custom headers, caching, and subscriptions.
When Agentif.jl is loaded, this package can register Agentif tools directly:
using Agentif
using ModelContextProtocol
tool = @tool "Echo text." echo(text::String) = text
server = MCPServer(MCPServerConfig(name="Agentif MCP", version="0.1.0"))
register_tool!(server, tool)See examples/ for calculator servers with and without OAuth. The docs include
a deeper walkthrough of the Auth0-federated calculator example.