ModelContextProtocol.jl
Julia implementation of the Model Context Protocol (MCP), enabling seamless integration between AI applications and external data sources, tools, and services.
Features
- ✅ Dual-Era Protocol Support - the full 2026-07-28 modern era (stateless requests,
server/discover, MRTR, the tasks extension, argument completion, subscriptions, header parameter mirroring, per-request logging) alongside classic sessions negotiated from2025-11-25back to2024-11-05 - ✅ Multiple Transports - stdio (default) and Streamable HTTP with Server-Sent Events and session management
- ✅ All Content Types - text, images, audio, embedded resources, and
resource_linkreferences - ✅ Structured Tool Output -
output_schemadeclarations withstructuredContentresults - ✅ Tool Annotations - behavioral hints (
readOnlyHint,destructiveHint, …) for client trust decisions - ✅ Progress Notifications - long-running tools report progress through context-aware handlers
- ✅ Background Tasks - the modern-era tasks extension (server-directed handoff, mid-task input, status notifications) plus legacy SEP-1686 tasks for 2025-11-25 sessions
- ✅ Argument Completion -
completion/completesuggestions for prompt arguments and template variables - ✅ OAuth Resource Server - bearer-token validation for HTTP (JWKS signature verification, GitHub tokens, JWT claims, RFC 7662 introspection) with RFC 9728 discovery
- ✅ Logging Control - runtime
logging/setLevel(legacy) and per-requestlogLevelopt-in (modern) - ✅ Auto-Registration - automatic component discovery from directory structure
- ✅ Type-Safe - leverages Julia's type system for robust implementations
Note: This is a server-side implementation. Legacy-era server-initiated elicitation/sampling (the modern era covers these via MRTR) and the OAuth Authorization Server (token issuance) are not implemented; SSE streams are not resumable via Last-Event-ID, and synchronous requests are served on a single serial loop (tasks move long tool calls off-loop).
Installation
using Pkg
Pkg.add("ModelContextProtocol")Quick Start
Create a simple MCP server with a tool:
using ModelContextProtocol
# Create a server with a simple echo tool
server = mcp_server(
name = "echo-server",
version = "1.0.0",
tools = [
MCPTool(
name = "echo",
description = "Echo back the input message",
parameters = [
ToolParameter(
name = "message",
type = "string",
description = "Message to echo",
required = true
)
],
handler = (params) -> TextContent(text = params["message"])
)
]
)
# Start the server (stdio transport by default)
start!(server)Using HTTP Transport
For web-based integrations, use the HTTP transport:
# Create server, then attach an HTTP transport
server = mcp_server(
name = "http-server",
version = "1.0.0",
tools = MCPTool[] # Your tools here
)
server.transport = HttpTransport(host = "127.0.0.1", port = 3000)
connect(server.transport)
start!(server)
# Test with curl
# curl -X POST http://127.0.0.1:3000/ \
# -H "Content-Type: application/json" \
# -d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":1}'Documentation Structure
- Examples - Complete working examples and common patterns
- Tools - Creating and using MCP tools
- Resources - Managing data sources and subscriptions
- Prompts - Defining prompt templates for LLMs
- Transports - Transport options and configuration
- The Modern Era - The 2026-07-28 stateless protocol surface
- Auto-Registration - Directory-based component organization
- Claude Desktop Integration - Integration with Claude Desktop
- Authentication - OAuth Resource Server setup for HTTP transport
- Deployment - Exposing a server to remote clients
- API Reference - Complete API documentation
Protocol Compliance
ModelContextProtocol.jl serves the full MCP 2026-07-28 modern era statelessly, alongside classic sessions negotiated at 2025-11-25 down through 2025-06-18 and 2025-03-26 to 2024-11-05. This includes:
- JSON-RPC 2.0 message protocol (batching rejected per spec)
- Tool discovery and invocation, structured output, annotations,
_meta - Resource management with subscriptions and
resource_linkreferences - Prompt templates with arguments and media content; argument completion
- Progress notifications (
notifications/progress) and logging (logging/setLevelfor sessions, per-requestlogLevelin the modern era) - Session management and OAuth Resource Server authentication for HTTP transport
- Modern-era tasks, MRTR,
subscriptions/listen, and SEP-2243 header validation
Basic Concepts
Tools
Tools are functions that can be invoked by the LLM:
tool = MCPTool(
name = "calculate",
description = "Perform basic arithmetic",
parameters = [
ToolParameter(name = "a", description = "First operand", type = "number", required = true),
ToolParameter(name = "b", description = "Second operand", type = "number", required = true),
ToolParameter(name = "op", description = "Operator: +, -, * or /", type = "string", required = true)
],
handler = function(params)
a, b = params["a"], params["b"]
result = if params["op"] == "+"
a + b
elseif params["op"] == "-"
a - b
elseif params["op"] == "*"
a * b
elseif params["op"] == "/"
a / b
else
error("Unknown operation")
end
return TextContent(text = string(result))
end
)Resources
Resources provide data access to the LLM:
resource = MCPResource(
uri = "file:///data/config.json",
name = "Application Config",
description = "Current application configuration",
mime_type = "application/json",
data_provider = () -> JSON3.read(read("config.json", String), Dict{String,Any})
)Prompts
Prompts are templates for generating conversations:
prompt = MCPPrompt(
name = "code_review",
description = "Request a code review",
arguments = [
PromptArgument(
name = "language",
description = "Programming language",
required = true
)
],
messages = [
PromptMessage(
content = TextContent(
text = "Please review this {language} code for best practices."
)
)
]
)Template placeholders like {language} are substituted from the arguments supplied in prompts/get.
Testing Your Server
With MCP Inspector
Test your server using the official MCP Inspector:
# For stdio transport (Inspector spawns the server command directly)
npx @modelcontextprotocol/inspector julia --project=. server.jl
# For HTTP transport
npx @modelcontextprotocol/inspector http://127.0.0.1:3000/
# Quick smoke test without the browser UI (CLI mode)
npx @modelcontextprotocol/inspector --cli julia --project=. server.jl --method tools/listWith curl (HTTP only)
# Initialize connection
curl -X POST http://127.0.0.1:3000/ \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}'
# List available tools
curl -X POST http://127.0.0.1:3000/ \
-H "Content-Type: application/json" \
-H "Mcp-Session-Id: <session-id-from-init>" \
-d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":2}'Next Steps
- Explore the Examples for complete working implementations
- Read the User Guide to understand each component type
- Check the API Reference for detailed function documentation
- Set up Claude Desktop Integration for real-world usage
Contributing
ModelContextProtocol.jl is part of the JuliaSMLM organization. Contributions are welcome! Please see our GitHub repository for issues and pull requests.
License
This project is licensed under the MIT License.