dox_mcp library
Model Context Protocol (MCP) server for the Dox framework.
Tools over the Streamable HTTP transport, with arguments checked by
dox_validation schemas, and signed session ids that work on every
isolate.
import 'package:dox_core/dox_core.dart';
import 'package:dox_mcp/dox_mcp.dart';
final McpServer mcp = McpServer(
name: 'my-app',
version: '1.0.0',
tools: <McpTool>[
McpTool.of(
name: 'echo',
description: 'Say the text back.',
input: v.object(<String, Schema<Object?>>{'text': v.string()}),
handler: (Map<String, dynamic> args, McpContext context) {
return McpToolResult.text(args['text'] as String);
},
),
],
);
Route.match(<String>['GET', 'POST', 'DELETE'], '/mcp', (DoxRequest req) {
return mcp.handle(req);
});
Classes
- JsonRpc
- Builds JSON-RPC 2.0 messages.
- JsonRpcCode
- JSON-RPC 2.0 error codes that MCP uses.
- McpContent
- One item of a tool result. MCP has text, image, audio and resource items. Most tools only need McpContent.text.
- McpContext
- What a tool call knows about its request.
- McpOAuth
-
OAuth 2.1 sign-in for an MCP server, as the MCP spec asks for. The
client gets only the address of the server, like
https://my.app/mcp. It finds the rest itself. - McpOAuthClient
-
A client that registered with
POST /oauth/register. - McpOAuthGrant
- A person said yes to a client. The app makes a token for it.
- McpOAuthTokens
- The app's part of the sign-in: its own tokens.
- McpServer
- An MCP server over the Streamable HTTP transport, for Dox routes.
- McpSessions
- Makes and checks MCP session ids.
- McpTool
- One MCP tool. Extend it, or use McpTool.of for a small one.
- McpToolResult
- The result of a tool call.
- SignedMcpSessions
- Session ids signed with HMAC-SHA256, so no store is needed.
Constants
- mcpProtocolHeader → const String
-
The header with the protocol version, sent after
initialize. - mcpSessionHeader → const String
- The header with the session id.
Exceptions / Errors
- McpError
- An error that becomes a JSON-RPC error response.
- McpOAuthException
-
An OAuth error. The client gets
{ error, error_description }.