McpServer class
High-level Model Context Protocol (MCP) server API.
Simplifies the registration of resources, tools, and prompts by providing
helper methods (resource
, tool
, prompt
) that configure the necessary
request handlers on an underlying Server instance.
Constructors
- McpServer.new(Implementation serverInfo, {ServerOptions? options})
- Creates an McpServer instance.
Properties
Methods
-
close(
) → Future< void> - Closes the server connection by closing the underlying transport.
-
connect(
Transport transport) → Future< void> -
Connects the server to a communication
transport
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
prompt(
String name, {String? description, Map< String, PromptArgumentDefinition> ? argsSchema, PromptCallback? callback}) → void - Registers a prompt or prompt template.
-
resource(
String name, String uri, ReadResourceCallback readCallback, {ResourceMetadata? metadata}) → void -
Registers a resource with a fixed, non-template
uri
. -
resourceTemplate(
String name, ResourceTemplateRegistration templateRegistration, ReadResourceTemplateCallback readCallback, {ResourceMetadata? metadata}) → void -
Registers resources based on a
templateRegistration
defining a URI pattern. -
tool(
String name, {String? description, Map< String, dynamic> ? inputSchemaProperties, Map<String, dynamic> ? outputSchemaProperties, ToolAnnotations? annotations, required ToolCallback callback}) → void - Registers a tool the client can invoke.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited