|
| 1 | +--- |
| 2 | +title: MCP Server Capabilities |
| 3 | +description: Configure and manage Model Context Protocol (MCP) server capabilities including tools, resources, and prompts |
| 4 | +--- |
| 5 | + |
| 6 | +# Model Context Protocol Server Capabilities |
| 7 | + |
| 8 | +The server can be configured with various capabilities: |
| 9 | + |
| 10 | +```java |
| 11 | +var capabilities = ServerCapabilities.builder() |
| 12 | + .resources(false, true) // Resource support with list changes notifications |
| 13 | + .tools(true) // Tool support with list changes notifications |
| 14 | + .prompts(true) // Prompt support with list changes notifications |
| 15 | + .logging() // Enable logging support (enabled by default with loging level INFO) |
| 16 | + .build(); |
| 17 | +``` |
| 18 | + |
| 19 | +## Logging Support |
| 20 | + |
| 21 | +The server provides structured logging capabilities that allow sending log messages to clients with different severity levels: |
| 22 | + |
| 23 | +```java |
| 24 | +// Send a log message to clients |
| 25 | +server.loggingNotification(LoggingMessageNotification.builder() |
| 26 | + .level(LoggingLevel.INFO) |
| 27 | + .logger("custom-logger") |
| 28 | + .data("Custom log message") |
| 29 | + .build()); |
| 30 | +``` |
| 31 | + |
| 32 | +Clients can control the minimum logging level they receive through the `mcpClient.setLoggingLevel(level)` request. Messages below the set level will be filtered out. |
| 33 | +Supported logging levels (in order of increasing severity): DEBUG (0), INFO (1), NOTICE (2), WARNING (3), ERROR (4), CRITICAL (5), ALERT (6), EMERGENCY (7) |
| 34 | + |
| 35 | +## Tool Registration |
| 36 | + |
| 37 | +<Tabs> |
| 38 | + <Tab title="Sync"> |
| 39 | +```java |
| 40 | +// Sync tool registration |
| 41 | +var syncToolRegistration = new McpServerFeatures.SyncToolRegistration( |
| 42 | + new Tool("calculator", "Basic calculator", Map.of( |
| 43 | + "operation", "string", |
| 44 | + "a", "number", |
| 45 | + "b", "number" |
| 46 | + )), |
| 47 | + arguments -> { |
| 48 | + // Tool implementation |
| 49 | + return new CallToolResult(result, false); |
| 50 | + } |
| 51 | +); |
| 52 | +``` |
| 53 | + </Tab> |
| 54 | + |
| 55 | + <Tab title="Async"> |
| 56 | +```java |
| 57 | +// Async tool registration |
| 58 | +var asyncToolRegistration = new McpServerFeatures.AsyncToolRegistration( |
| 59 | + new Tool("calculator", "Basic calculator", Map.of( |
| 60 | + "operation", "string", |
| 61 | + "a", "number", |
| 62 | + "b", "number" |
| 63 | + )), |
| 64 | + arguments -> { |
| 65 | + // Tool implementation |
| 66 | + return Mono.just(new CallToolResult(result, false)); |
| 67 | + } |
| 68 | +); |
| 69 | +``` |
| 70 | + </Tab> |
| 71 | +</Tabs> |
| 72 | + |
| 73 | +## Resource Registration |
| 74 | + |
| 75 | +<Tabs> |
| 76 | + <Tab title="Sync"> |
| 77 | +```java |
| 78 | +// Sync resource registration |
| 79 | +var syncResourceRegistration = new McpServerFeatures.SyncResourceRegistration( |
| 80 | + new Resource("custom://resource", "name", "description", "mime-type", null), |
| 81 | + request -> { |
| 82 | + // Resource read implementation |
| 83 | + return new ReadResourceResult(contents); |
| 84 | + } |
| 85 | +); |
| 86 | +``` |
| 87 | + </Tab> |
| 88 | + |
| 89 | + <Tab title="Async"> |
| 90 | +```java |
| 91 | +// Async resource registration |
| 92 | +var asyncResourceRegistration = new McpServerFeatures.AsyncResourceRegistration( |
| 93 | + new Resource("custom://resource", "name", "description", "mime-type", null), |
| 94 | + request -> { |
| 95 | + // Resource read implementation |
| 96 | + return Mono.just(new ReadResourceResult(contents)); |
| 97 | + } |
| 98 | +); |
| 99 | +``` |
| 100 | + </Tab> |
| 101 | +</Tabs> |
| 102 | + |
| 103 | +## Prompt Registration |
| 104 | + |
| 105 | +<Tabs> |
| 106 | + <Tab title="Sync"> |
| 107 | +```java |
| 108 | +// Sync prompt registration |
| 109 | +var syncPromptRegistration = new McpServerFeatures.SyncPromptRegistration( |
| 110 | + new Prompt("greeting", "description", List.of( |
| 111 | + new PromptArgument("name", "description", true) |
| 112 | + )), |
| 113 | + request -> { |
| 114 | + // Prompt implementation |
| 115 | + return new GetPromptResult(description, messages); |
| 116 | + } |
| 117 | +); |
| 118 | +``` |
| 119 | + </Tab> |
| 120 | + |
| 121 | + <Tab title="Async"> |
| 122 | +```java |
| 123 | +// Async prompt registration |
| 124 | +var asyncPromptRegistration = new McpServerFeatures.AsyncPromptRegistration( |
| 125 | + new Prompt("greeting", "description", List.of( |
| 126 | + new PromptArgument("name", "description", true) |
| 127 | + )), |
| 128 | + request -> { |
| 129 | + // Prompt implementation |
| 130 | + return Mono.just(new GetPromptResult(description, messages)); |
| 131 | + } |
| 132 | +); |
| 133 | +``` |
| 134 | + </Tab> |
| 135 | +</Tabs> |
| 136 | + |
| 137 | +# Error Handling |
| 138 | + |
| 139 | +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. |
0 commit comments