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
Set Maven version to 0.14.0 and align llms.txt / llms-full.txt with README
and implementation (YAML defaults, completions API, structured content).
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. Use an executable JAR setup in your own project if you need `java -jar` with a single file.
161
+
159
162
## Core Components
160
163
161
164
### Resources
@@ -167,9 +170,10 @@ Resource components are used to expose data to LLMs, similar to GET requests in
167
170
| Parameter | Description | Required |
168
171
|-----------|-------------|----------|
169
172
| `uri` | Unique identifier of the resource (URI format) | Yes |
| `description` | Prompt description for LLM understanding | No (defaults to prompt `name`, then method name) |
203
207
| `name` | Prompt name (defaults to method name) | No |
204
208
| `title` | Prompt title for display purposes | No |
205
209
@@ -208,35 +212,74 @@ Prompt components are used to define reusable prompt templates.
208
212
| Parameter | Description | Required |
209
213
|-----------|-------------|----------|
210
214
| `name` | Parameter name | Yes |
211
-
| `description` | Parameter description | Yes |
212
-
| `required` | Whether the parameter is required | No |
215
+
| `description` | Parameter description | No (defaults to `name`) |
216
+
| `required` | Whether the parameter is required | No (default `true`) |
213
217
214
218
### Completions
215
219
216
220
Completions provide auto-complete suggestions for resource URIs and prompt arguments.
217
221
222
+
Handlers must **return** `McpCompleteCompletion` and take **exactly one** parameter of type `McpSchema.CompleteRequest.CompleteArgument` (`name()` and `value()` identify the argument being completed).
`@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.
| `streamable.port` | HTTP port for STREAMABLE mode | `8080` |
285
344
286
345
## Profile-based Configuration
287
346
@@ -344,32 +403,48 @@ public int add(
344
403
345
404
## Structured Content
346
405
347
-
Tools can return structured content for rich responses:
406
+
Tools can return structured content by returning a type that **implements** `McpStructuredContent` (often a `record` with `@McpJsonSchemaProperty` on fields). There is no `McpStructuredContent.of(...)` helper.
@McpToolParam(name = "id", description = "User ID") String id
353
-
) {
354
-
User user = userService.findById(id);
355
-
return McpStructuredContent.of(user);
428
+
public User getUser(@McpToolParam(name = "id", description = "User ID") String id) {
429
+
return new User(id, "Ada");
356
430
}
357
431
```
358
432
359
433
## Error Handling
360
434
361
-
When a tool encounters an error, you can return an error result:
435
+
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).
436
+
437
+
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:
362
438
363
439
```java
364
440
@McpTool(description = "Divide two numbers")
365
-
public Number divide(
441
+
public String divide(
366
442
@McpToolParam(name = "a", description = "Dividend") double a,
367
-
@McpToolParam(name = "b", description = "Divisor") double b
368
-
) {
369
-
if (b == 0) {
370
-
return McpStructuredContent.error("Division by zero is not allowed");
371
-
}
372
-
return a / b;
443
+
@McpToolParam(name = "b", description = "Divisor") double b) {
444
+
if (b == 0) {
445
+
return "Cannot divide by zero.";
446
+
}
447
+
return Double.toString(a / b);
373
448
}
374
449
```
375
450
@@ -413,25 +488,29 @@ your-mcp-project/
413
488
│ └── example/
414
489
│ └── McpServerTest.java # Unit tests
415
490
└── target/
416
-
└── your-app.jar # Executable JAR
491
+
└── *.jar # Build output (name depends on your project)
417
492
```
418
493
419
494
## Custom JSON Schema
420
495
421
-
For complex parameter types, you can define custom JSON schemas:
496
+
For complex tool parameter or result types, annotate the type with `@McpJsonSchemaDefinition` and annotate fields (or record components) with `@McpJsonSchemaProperty` (JSON types are inferred from Java types).
0 commit comments