You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sync YAML keys and defaults, dependency coordinates, completions
handlers, structured content, and error-handling guidance with the code.
Co-authored-by: Cursor <cursoragent@cursor.com>
Run `MyFirstMcpServer` from your IDE, or use `java -cp ...` with your compiled classes and dependencies on the classpath. Your own project needs an executable JAR setup (for example Spring Boot or the Maven Shade plugin) if you want `java -jar` with a single file.
146
+
146
147
That's it! Your MCP server is now ready to serve resources, tools, and prompts!
|`description`| Parameter description | No (defaults to `name`)|
143
+
|`required`| Whether the parameter is required | No (default `true`)|
143
144
144
145
## Completions
145
146
146
147
Completions provide auto-complete suggestions for resource URIs and prompt arguments.
147
148
149
+
Handlers must **return**`McpCompleteCompletion` and take **exactly one** parameter of type `McpSchema.CompleteRequest.CompleteArgument` (the argument being completed has `name()` and `value()` from the MCP request).
`@McpPromptCompletion.name` must match the **registered prompt name** (by default, the Java method name of the `@McpPrompt` method). Filter by `argument.name()` when one prompt has multiple parameters.
@@ -248,31 +281,50 @@ If no package path is specified, the package containing the main method will be
248
281
249
282
## Structured Content
250
283
251
-
Tools can return structured content for rich responses:
284
+
Tools can return structured content for rich responses by returning a type that **implements**`McpStructuredContent` (often a `record` with `@McpJsonSchemaProperty` on fields). There is no `McpStructuredContent.of(...)` helper in the API.
252
285
253
286
```java
254
-
@McpTool(description="Get user details")
255
-
publicMcpStructuredContent<User> getUser(
256
-
@McpToolParam(name="id", description="User ID") String id
When a tool encounters an error, you can return an error result:
316
+
If a tool method **throws any exception**, the server returns a `CallToolResult` with `isError` set to `true` and a generic method-invocation error message (the exception message is not forwarded to the client today).
317
+
318
+
For expected failures such as validation, return a normal value (for example a `String`) so the tool call remains a successful result with `isError` false:
266
319
267
320
```java
268
321
@McpTool(description="Divide two numbers")
269
-
publicNumber divide(
322
+
publicString divide(
270
323
@McpToolParam(name="a", description="Dividend") double a,
271
-
@McpToolParam(name="b", description="Divisor") double b
272
-
) {
273
-
if (b ==0) {
274
-
returnMcpStructuredContent.error("Division by zero is not allowed");
275
-
}
276
-
return a / b;
324
+
@McpToolParam(name="b", description="Divisor") double b) {
0 commit comments