mcp_server library

Classes

ApiKeyValidator
Simple API key validator
AuthContext
Authorization context for MCP requests
AuthMiddleware
Authentication middleware for HTTP requests
AuthResult
Authentication result
BatchRequestTracker
Batch request tracker for handling JSON-RPC batch requests
CachedResource
Cached resource item for performance optimization
CallToolResult
Tool call result
CancellationToken
Cancellation token for async operations
ClientSession
Client session information
Content
Base class for all MCP content types (2025-03-26 compliant)
CreateMessageRequest
Create message request for sampling
CreateMessageResult
Create message result from sampling
DeprecationInfo
Deprecation information
ErrorCode
Error codes for standardized error handling
EventMessage
Event message with optional ID for SSE
Failure<T, E extends Object>
Represents a failed result
GetPromptResult
Get prompt result
ImageContent
Image content representation
JsonRpcMessage
JSON-RPC message
Level
Levels to control logging output. Logging can be enabled to include all levels above certain Level. Levels are ordered using an integer value Level.value. The predefined Level constants below are sorted as follows (in descending order): Level.SHOUT, Level.SEVERE, Level.WARNING, Level.INFO, Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, and Level.ALL.
Logger
Use a Logger to log debug messages.
LoggingCapability
Logging capability
LogRecord
A log entry representation used to propagate information from Logger to individual handlers.
McpErrorCodes
MCP Error codes as defined in the specification
McpMethodAuth
MCP method authorization configuration
McpMethods
Standard MCP methods that must be implemented
McpProtocol
MCP Protocol Version constants and definitions
McpServer
Modern MCP Server factory with enhanced configuration and error handling
McpServerConfig
Configuration for creating MCP servers
Message
Message model for prompt system
ModelHint
Model hint for sampling
ModelPreferences
Model preferences for sampling
OAuthTokenValidator
OAuth 2.1 token validator
PendingOperation
Pending operation for cancellation support
ProgressCapability
Progress capability
ProgressNotification
Progress notification data (2025-03-26)
Prompt
Prompt definition
PromptArgument
Prompt argument definition
PromptMessage
Prompt message (2025-03-26)
PromptsCapability
Prompts capability
ReadResourceResult
Resource read result
Resource
Resource definition
ResourceContent
Resource content representation
ResourceContentInfo
Resource content info (used in ReadResourceResult)
ResourcesCapability
Resources capability
ResourceTemplate
Resource template definition
ResourceUsage
Resource usage indicators
Result<T, E extends Object>
A sealed class representing the result of an operation that can succeed or fail
Results
Utility functions for working with Results
Root
Root definition for filesystem access
RootsCapability
Roots capability
SamplingCapability
Sampling capability
Server
Main MCP Server class that handles all server-side protocol operations
ServerCapabilities
Server capabilities configuration for MCP 2025-03-26 protocol
ServerHealth
Server health information
ServerInterface
Interface for server to expose key functionality for testing
ServerTransport
Abstract base class for server transport implementations
SseServerTransport
Transport implementation using Server-Sent Events (SSE) over HTTP
SseStreamInfo
SSE stream information for request-specific streams
SseTransportConfig
StdioServerTransport
Transport implementation using standard input/output streams
StdioTransportConfig
StreamableHttpServerConfig
Configuration for StreamableHTTP server transport
StreamableHttpServerTransport
MCP 2025-03-26 StreamableHTTP Server Transport Implementation Supports both JSON responses and SSE streaming according to MCP standard
StreamableHttpTransportConfig
Success<T, E extends Object>
Represents a successful result
TextContent
Text content representation
TokenValidator
Token validation interface
Tool
Tool definition (2025-03-26 compliant)
ToolAnnotationBuilder
Tool annotation builder for creating standard annotations
ToolAnnotationKeys
Standard tool annotation keys defined in MCP 2025-03-26
ToolAnnotationPresets
Common tool annotation presets
ToolAnnotationUtils
Utility functions for working with tool annotations
ToolsCapability
Tools capability
TransportConfig
Configuration for transport connections

Enums

MCPContentType
McpLogLevel
Log levels for MCP protocol
MessageRole
Base content type enum for MCP
PromptMessageRole
Prompt message roles
ToolPriority
Tool priority levels

Extensions

FutureResultExtensions on Future<Result<T, E>>
Extension methods for Future<Result>
LoggerExtensions on Logger
OAuthServerMethods on Server

Constants

defaultLevel → const Level
The default Level.
getStreamKey → const String

Properties

hierarchicalLoggingEnabled bool
Whether to allow fine-grain logging and configuration of loggers in a hierarchy.
getter/setter pair
recordStackTraceAtLevel Level
Automatically record stack traces for any message of this level or above.
getter/setter pair

Typedefs

IsCancelledCheck = bool Function()
Callback type for checking if operation is cancelled
MCPServer = McpServer
ProgressCallback = void Function(double progress, String message)
Callback type for tool execution progress updates
PromptHandler = Future Function(Map<String, dynamic> arguments)
Type definition for prompt handler functions
ResourceHandler = Future Function(String uri, Map<String, dynamic> params)
Type definition for resource handler functions
SseServerConfig = SseTransportConfig
ToolHandler = Future Function(Map<String, dynamic> arguments)
Type definition for tool handler functions with cancellation and progress reporting

Exceptions / Errors

CancelledException
Exception thrown when an operation is cancelled
McpError
Error class for MCP-related errors