Skip to content

Commit 501c27d

Browse files
committed
docs: update documentation for SDK v0.13.0
- Update index page with improved server mode descriptions and quick links - Revamp getting started guide with new configuration approach - Enhance components documentation with detailed annotation parameters - Add new sections for completions, structured content, and error handling
1 parent 96b7abd commit 501c27d

3 files changed

Lines changed: 237 additions & 74 deletions

File tree

docs/components.md

Lines changed: 119 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ public class MyResources {
2929
}
3030
```
3131

32-
### Annotation Explanation
32+
### Annotation Parameters
3333

34-
- `@McpResource`: Marks a method as an MCP resource
35-
- `uri`: Unique identifier of the resource, following URI format
36-
- `description`: Resource description for LLM to understand the resource's purpose
34+
| Parameter | Description | Required |
35+
|----------------|------------------------------------------------|----------|
36+
| `uri` | Unique identifier of the resource (URI format) | Yes |
37+
| `description` | Resource description for LLM understanding | Yes |
38+
| `name` | Resource name (defaults to method name) | No |
39+
| `mimeType` | MIME type of the resource content | No |
3740

3841
## Tools
3942

@@ -48,14 +51,16 @@ import com.github.thought2code.mcp.annotated.annotation.McpToolParam;
4851
public class MyTools {
4952
@McpTool(description = "Calculate the sum of two numbers")
5053
public int add(
51-
@McpToolParam(name = "a", description = "First number", required = true) int a,
52-
@McpToolParam(name = "b", description = "Second number", required = true) int b
54+
@McpToolParam(name = "a", description = "First number") int a,
55+
@McpToolParam(name = "b", description = "Second number") int b
5356
) {
5457
return a + b;
5558
}
5659

5760
@McpTool(description = "Read complete file contents with UTF-8 encoding")
58-
public String readFile(@McpToolParam(name = "path", description = "File path", required = true) String path) {
61+
public String readFile(
62+
@McpToolParam(name = "path", description = "File path") String path
63+
) {
5964
try {
6065
return Files.readString(Path.of(path));
6166
} catch (IOException e) {
@@ -65,7 +70,23 @@ public class MyTools {
6570
}
6671
```
6772

68-
### Annotation Explanation
73+
### Annotation Parameters
74+
75+
#### @McpTool
76+
77+
| Parameter | Description | Required |
78+
|---------------|------------------------------------------|----------|
79+
| `description` | Tool description for LLM understanding | Yes |
80+
| `name` | Tool name (defaults to method name) | No |
81+
| `title` | Tool title for display purposes | No |
82+
83+
#### @McpToolParam
84+
85+
| Parameter | Description | Required |
86+
|---------------|------------------------------------------|----------|
87+
| `name` | Parameter name | Yes |
88+
| `description` | Parameter description | Yes |
89+
| `required` | Whether the parameter is required | No |
6990

7091
- `@McpTool`: Marks a method as an MCP tool
7192
- `@McpToolParam`: Marks method parameters as tool parameters
@@ -86,54 +107,90 @@ import com.github.thought2code.mcp.annotated.annotation.McpPromptParam;
86107
public class MyPrompts {
87108
@McpPrompt(description = "Generate code for a given task")
88109
public String generateCode(
89-
@McpPromptParam(name = "language", description = "Programming language", required = true) String language,
90-
@McpPromptParam(name = "task", description = "Task description", required = true) String task
110+
@McpPromptParam(name = "language", description = "Programming language") String language,
111+
@McpPromptParam(name = "task", description = "Task description") String task
91112
) {
92113
return String.format("Write %s code to: %s", language, task);
93114
}
94115

95116
@McpPrompt(description = "Format text as specified style")
96117
public String formatText(
97-
@McpPromptParam(name = "text", description = "Text to format", required = true) String text,
98-
@McpPromptParam(name = "style", description = "Format style (e.g., formal, casual, technical)", required = true) String style
118+
@McpPromptParam(name = "text", description = "Text to format") String text,
119+
@McpPromptParam(name = "style", description = "Format style (e.g., formal, casual, technical)") String style
99120
) {
100121
return String.format("Rewrite the following text in a %s style: %s", style, text);
101122
}
102123
}
103124
```
104125

105-
### Annotation Explanation
126+
### Annotation Parameters
106127

107-
- `@McpPrompt`: Marks a method as an MCP prompt
108-
- `@McpPromptParam`: Marks method parameters as prompt parameters
109-
- `name`: Parameter name
110-
- `description`: Parameter description
111-
- `required`: Whether the parameter is required
128+
#### @McpPrompt
129+
130+
| Parameter | Description | Required |
131+
|---------------|------------------------------------------|----------|
132+
| `description` | Prompt description for LLM understanding | Yes |
133+
| `name` | Prompt name (defaults to method name) | No |
134+
| `title` | Prompt title for display purposes | No |
135+
136+
#### @McpPromptParam
137+
138+
| Parameter | Description | Required |
139+
|---------------|------------------------------------------|----------|
140+
| `name` | Parameter name | Yes |
141+
| `description` | Parameter description | Yes |
142+
| `required` | Whether the parameter is required | No |
143+
144+
## Completions
145+
146+
Completions provide auto-complete suggestions for resource URIs and prompt arguments.
147+
148+
### Resource Completions
149+
150+
```java
151+
import com.github.thought2code.mcp.annotated.annotation.McpResourceCompletion;
152+
153+
public class MyCompletions {
154+
@McpResourceCompletion(uri = "file://")
155+
public List<String> completeFilePath(String uri, String cursorValue) {
156+
// Return matching file paths
157+
return Files.list(Paths.get(cursorValue))
158+
.map(Path::toString)
159+
.collect(Collectors.toList());
160+
}
161+
}
162+
```
163+
164+
### Prompt Completions
165+
166+
```java
167+
import com.github.thought2code.mcp.annotated.annotation.McpPromptCompletion;
168+
169+
public class MyCompletions {
170+
@McpPromptCompletion(promptName = "generateCode", argumentName = "language")
171+
public List<String> completeLanguage(String value) {
172+
return Arrays.asList("Java", "Python", "JavaScript", "Go", "Rust");
173+
}
174+
}
175+
```
112176

113177
## Multilingual Support
114178

115179
This SDK has built-in multilingual support, which can be enabled through the `@McpI18nEnabled` annotation.
116180

117-
### Configure Multilingual
181+
### Enable i18n
118182

119183
```java
120184
@McpServerApplication
121185
@McpI18nEnabled(resourceBundleBaseName = "messages")
122186
public class I18nMcpServer {
123-
/**
124-
* Main method to start the MCP server with i18n support.
125-
*
126-
* @param args Command line arguments.
127-
*/
128187
public static void main(String[] args) {
129-
McpServerConfiguration.Builder configuration =
130-
McpServerConfiguration.builder().name("i18n-mcp-server").version("1.0.0");
131-
McpServers.run(I18nMcpServer.class, args).startStdioServer(configuration);
188+
McpApplication.run(I18nMcpServer.class, args);
132189
}
133190
}
134191
```
135192

136-
### Internationalization Resource Files
193+
### Create Resource Bundles
137194

138195
Create `messages.properties` file:
139196

@@ -161,7 +218,7 @@ prompt.generate.code.param.language.description=编程语言
161218
prompt.generate.code.param.task.description=任务描述
162219
```
163220

164-
Using internationalized messages in components:
221+
### Use i18n in Components
165222

166223
```java
167224
@McpTool(description = "tool.add.description")
@@ -177,6 +234,8 @@ public int add(
177234

178235
After defining MCP components, they will be automatically registered to the server. You just need to ensure that the component classes are in the package scanning path of the server application.
179236

237+
### Specify Package Path
238+
180239
If you need to specify a specific package path, you can use the following methods:
181240

182241
```java
@@ -186,3 +245,34 @@ If you need to specify a specific package path, you can use the following method
186245
```
187246

188247
If no package path is specified, the package containing the main method will be scanned.
248+
249+
## Structured Content
250+
251+
Tools can return structured content for rich responses:
252+
253+
```java
254+
@McpTool(description = "Get user details")
255+
public McpStructuredContent<User> getUser(
256+
@McpToolParam(name = "id", description = "User ID") String id
257+
) {
258+
User user = userService.findById(id);
259+
return McpStructuredContent.of(user);
260+
}
261+
```
262+
263+
## Error Handling
264+
265+
When a tool encounters an error, you can return an error result:
266+
267+
```java
268+
@McpTool(description = "Divide two numbers")
269+
public Number divide(
270+
@McpToolParam(name = "a", description = "Dividend") double a,
271+
@McpToolParam(name = "b", description = "Divisor") double b
272+
) {
273+
if (b == 0) {
274+
return McpStructuredContent.error("Division by zero is not allowed");
275+
}
276+
return a / b;
277+
}
278+
```

0 commit comments

Comments
 (0)