Skip to main content

MCP Transports

Prism supports two transport modes for MCP communication. Choose based on how your AI client connects.

Stdio Transport

The stdio transport reads JSON-RPC messages from stdin and writes responses to stdout. This is the standard for CLI-based MCP servers that AI clients launch as subprocesses.
Stdio Server
@main
struct MyMCPServer {
    static func main() async throws {
        let mcp = PrismMCPServer(name: "my-tools", version: "1.0.0")
        
        await mcp.registerTool("hello", description: "Say hello", inputSchema: [:]) { _ in
            PrismMCPToolResult(content: [.text("Hello from Prism!")], isError: false)
        }
        
        let transport = PrismMCPStdioTransport(server: mcp)
        await transport.start()  // Blocks, reading stdin
    }
}

Claude Desktop Configuration

Add your server to Claude Desktop’s config file:
claude_desktop_config.json
{
  "mcpServers": {
    "my-tools": {
      "command": "/path/to/your/binary",
      "args": []
    }
  }
}
Build your server as a release binary with swift build -c release, then point Claude Desktop to the binary in .build/release/.

HTTP Transport

The HTTP transport integrates with your Prism web server, handling MCP requests over HTTP POST and server notifications over SSE:
HTTP Transport
let server = PrismHTTPServer(port: 8080)
let mcp = PrismMCPServer(name: "web-tools", version: "1.0.0")

// Register tools...
await mcp.registerTool("search", description: "Search", inputSchema: ["q": "string"]) { args in
    PrismMCPToolResult(content: [.text("Results for: \(args["q"] ?? "")")], isError: false)
}

// Mount MCP on the HTTP server
let mcpTransport = PrismMCPHTTPTransport(server: mcp, path: "/mcp")
await server.use(mcpTransport)

try await server.start()

Endpoints

MethodPathPurpose
POST/mcpSend JSON-RPC requests
GET/mcp/sseSSE stream for server notifications

Testing with curl

Initialize
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"clientInfo":{"name":"test"}}}'
List Tools
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'
Call a Tool
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"search","arguments":{"q":"prism"}}}'

Choosing a Transport

Use Stdio When...

Building CLI tools, local development servers, or Claude Desktop integrations. The AI client launches your binary as a subprocess.

Use HTTP When...

Running a web service, hosting MCP alongside a REST/GraphQL API, or serving remote AI clients over the network.

What’s Next

Tools

Build powerful tools for AI assistants

Resources

Expose data as readable resources