Skip to content

Latest commit

 

History

History
139 lines (121 loc) · 4.05 KB

mcp-capabilities.mdx

File metadata and controls

139 lines (121 loc) · 4.05 KB
title description
MCP Server Capabilities
Configure and manage Model Context Protocol (MCP) server capabilities including tools, resources, and prompts

Model Context Protocol Server Capabilities

The server can be configured with various capabilities:

var capabilities = ServerCapabilities.builder()
    .resources(false, true)  // Resource support with list changes notifications
    .tools(true)            // Tool support with list changes notifications
    .prompts(true)          // Prompt support with list changes notifications
    .logging()              // Enable logging support (enabled by default with loging level INFO)
    .build();

Logging Support

The server provides structured logging capabilities that allow sending log messages to clients with different severity levels:

// Send a log message to clients
server.loggingNotification(LoggingMessageNotification.builder()
    .level(LoggingLevel.INFO)
    .logger("custom-logger")
    .data("Custom log message")
    .build());

Clients can control the minimum logging level they receive through the mcpClient.setLoggingLevel(level) request. Messages below the set level will be filtered out. Supported logging levels (in order of increasing severity): DEBUG (0), INFO (1), NOTICE (2), WARNING (3), ERROR (4), CRITICAL (5), ALERT (6), EMERGENCY (7)

Tool Registration

```java // Sync tool registration var syncToolRegistration = new McpServerFeatures.SyncToolRegistration( new Tool("calculator", "Basic calculator", Map.of( "operation", "string", "a", "number", "b", "number" )), arguments -> { // Tool implementation return new CallToolResult(result, false); } ); ``` ```java // Async tool registration var asyncToolRegistration = new McpServerFeatures.AsyncToolRegistration( new Tool("calculator", "Basic calculator", Map.of( "operation", "string", "a", "number", "b", "number" )), arguments -> { // Tool implementation return Mono.just(new CallToolResult(result, false)); } ); ```

Resource Registration

```java // Sync resource registration var syncResourceRegistration = new McpServerFeatures.SyncResourceRegistration( new Resource("custom://resource", "name", "description", "mime-type", null), request -> { // Resource read implementation return new ReadResourceResult(contents); } ); ``` ```java // Async resource registration var asyncResourceRegistration = new McpServerFeatures.AsyncResourceRegistration( new Resource("custom://resource", "name", "description", "mime-type", null), request -> { // Resource read implementation return Mono.just(new ReadResourceResult(contents)); } ); ```

Prompt Registration

```java // Sync prompt registration var syncPromptRegistration = new McpServerFeatures.SyncPromptRegistration( new Prompt("greeting", "description", List.of( new PromptArgument("name", "description", true) )), request -> { // Prompt implementation return new GetPromptResult(description, messages); } ); ``` ```java // Async prompt registration var asyncPromptRegistration = new McpServerFeatures.AsyncPromptRegistration( new Prompt("greeting", "description", List.of( new PromptArgument("name", "description", true) )), request -> { // Prompt implementation return Mono.just(new GetPromptResult(description, messages)); } ); ```

Error Handling

The SDK provides comprehensive error handling through the McpError class, covering protocol compatibility, transport communication, JSON-RPC messaging, tool execution, resource management, prompt handling, timeouts, and connection issues. This unified error handling approach ensures consistent and reliable error management across both synchronous and asynchronous operations.