Skip to content

Commit e2d170a

Browse files
committed
Rename build-time component types for consistent server.component naming.
Align ComponentProcessor, ComponentProvider, CompletionResult, and GeneratedComponentProvider with updated docs and error messages.
1 parent df20d40 commit e2d170a

23 files changed

Lines changed: 161 additions & 169 deletions

docs/components.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -146,39 +146,40 @@ public class MyPrompts {
146146

147147
Completions provide auto-complete suggestions for resource URIs and prompt arguments.
148148

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).
149+
Handlers must **return** `CompletionResult` and take **exactly one** parameter of type `McpSchema.CompleteRequest.CompleteArgument` (the argument being completed has `name()` and `value()` from the MCP request).
150150

151151
### Resource Completions
152152

153153
```java
154154
import com.github.thought2code.mcp.annotated.annotation.McpResourceCompletion;
155-
import com.github.thought2code.mcp.annotated.server.component.completion.McpCompleteCompletion;
155+
import com.github.thought2code.mcp.annotated.server.component.completion.CompletionResult;
156156
import io.modelcontextprotocol.spec.McpSchema;
157+
157158
import java.nio.file.Files;
158159
import java.nio.file.Path;
159160
import java.nio.file.Paths;
160161
import java.util.List;
161162
import java.util.stream.Collectors;
162163

163164
public class MyCompletions {
164-
@McpResourceCompletion(uri = "file://")
165-
public McpCompleteCompletion completeFileUri(McpSchema.CompleteRequest.CompleteArgument argument) {
166-
String prefix = argument.value() != null ? argument.value() : "";
167-
try {
168-
List<String> paths =
169-
Files.list(Paths.get(prefix.isEmpty() ? "." : prefix))
170-
.map(Path::toString)
171-
.limit(50)
172-
.collect(Collectors.toList());
173-
return McpCompleteCompletion.builder()
174-
.values(paths)
175-
.total(paths.size())
176-
.hasMore(false)
177-
.build();
178-
} catch (Exception e) {
179-
return McpCompleteCompletion.empty();
165+
@McpResourceCompletion(uri = "file://")
166+
public CompletionResult completeFileUri(McpSchema.CompleteRequest.CompleteArgument argument) {
167+
String prefix = argument.value() != null ? argument.value() : "";
168+
try {
169+
List<String> paths =
170+
Files.list(Paths.get(prefix.isEmpty() ? "." : prefix))
171+
.map(Path::toString)
172+
.limit(50)
173+
.collect(Collectors.toList());
174+
return CompletionResult.builder()
175+
.values(paths)
176+
.total(paths.size())
177+
.hasMore(false)
178+
.build();
179+
} catch (Exception e) {
180+
return CompletionResult.empty();
181+
}
180182
}
181-
}
182183
}
183184
```
184185

@@ -188,22 +189,23 @@ public class MyCompletions {
188189

189190
```java
190191
import com.github.thought2code.mcp.annotated.annotation.McpPromptCompletion;
191-
import com.github.thought2code.mcp.annotated.server.component.completion.McpCompleteCompletion;
192+
import com.github.thought2code.mcp.annotated.server.component.completion.CompletionResult;
192193
import io.modelcontextprotocol.spec.McpSchema;
194+
193195
import java.util.List;
194196

195197
public class MyPromptCompletions {
196-
@McpPromptCompletion(name = "generateCode")
197-
public McpCompleteCompletion completeGenerateCode(McpSchema.CompleteRequest.CompleteArgument argument) {
198-
if (!"language".equals(argument.name())) {
199-
return McpCompleteCompletion.empty();
198+
@McpPromptCompletion(name = "generateCode")
199+
public CompletionResult completeGenerateCode(McpSchema.CompleteRequest.CompleteArgument argument) {
200+
if (!"language".equals(argument.name())) {
201+
return CompletionResult.empty();
202+
}
203+
return CompletionResult.builder()
204+
.values(List.of("Java", "Python", "JavaScript", "Go", "Rust"))
205+
.total(5)
206+
.hasMore(false)
207+
.build();
200208
}
201-
return McpCompleteCompletion.builder()
202-
.values(List.of("Java", "Python", "JavaScript", "Go", "Rust"))
203-
.total(5)
204-
.hasMore(false)
205-
.build();
206-
}
207209
}
208210
```
209211

llms-full.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ Prompt components are used to define reusable prompt templates.
219219

220220
Completions provide auto-complete suggestions for resource URIs and prompt arguments.
221221

222-
Handlers must **return** `McpCompleteCompletion` and take **exactly one** parameter of type `McpSchema.CompleteRequest.CompleteArgument` (`name()` and `value()` identify the argument being completed).
222+
Handlers must **return** `CompletionResult` and take **exactly one** parameter of type `McpSchema.CompleteRequest.CompleteArgument` (`name()` and `value()` identify the argument being completed).
223223

224224
#### Resource Completions
225225

226226
```java
227227
import com.github.thought2code.mcp.annotated.annotation.McpResourceCompletion;
228-
import com.github.thought2code.mcp.annotated.server.component.McpCompleteCompletion;
228+
import com.github.thought2code.mcp.annotated.server.component.completion.CompletionResult;
229229
import io.modelcontextprotocol.spec.McpSchema;
230230
import java.nio.file.Files;
231231
import java.nio.file.Path;
@@ -234,21 +234,21 @@ import java.util.List;
234234
import java.util.stream.Collectors;
235235

236236
@McpResourceCompletion(uri = "file://")
237-
public McpCompleteCompletion completeFileUri(McpSchema.CompleteRequest.CompleteArgument argument) {
237+
public CompletionResult completeFileUri(McpSchema.CompleteRequest.CompleteArgument argument) {
238238
String prefix = argument.value() != null ? argument.value() : "";
239239
try {
240240
List<String> paths =
241241
Files.list(Paths.get(prefix.isEmpty() ? "." : prefix))
242242
.map(Path::toString)
243243
.limit(50)
244244
.collect(Collectors.toList());
245-
return McpCompleteCompletion.builder()
245+
return CompletionResult.builder()
246246
.values(paths)
247247
.total(paths.size())
248248
.hasMore(false)
249249
.build();
250250
} catch (Exception e) {
251-
return McpCompleteCompletion.empty();
251+
return CompletionResult.empty();
252252
}
253253
}
254254
```
@@ -259,16 +259,16 @@ public McpCompleteCompletion completeFileUri(McpSchema.CompleteRequest.CompleteA
259259

260260
```java
261261
import com.github.thought2code.mcp.annotated.annotation.McpPromptCompletion;
262-
import com.github.thought2code.mcp.annotated.server.component.McpCompleteCompletion;
262+
import com.github.thought2code.mcp.annotated.server.component.completion.CompletionResult;
263263
import io.modelcontextprotocol.spec.McpSchema;
264264
import java.util.List;
265265

266266
@McpPromptCompletion(name = "generateCode")
267-
public McpCompleteCompletion completeGenerateCode(McpSchema.CompleteRequest.CompleteArgument argument) {
267+
public CompletionResult completeGenerateCode(McpSchema.CompleteRequest.CompleteArgument argument) {
268268
if (!"language".equals(argument.name())) {
269-
return McpCompleteCompletion.empty();
269+
return CompletionResult.empty();
270270
}
271-
return McpCompleteCompletion.builder()
271+
return CompletionResult.builder()
272272
.values(List.of("Java", "Python", "JavaScript", "Go", "Rust"))
273273
.total(5)
274274
.hasMore(false)

src/main/java/com/github/thought2code/mcp/annotated/annotation/McpPromptCompletion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.thought2code.mcp.annotated.annotation;
22

3-
import com.github.thought2code.mcp.annotated.server.component.completion.McpCompleteCompletion;
3+
import com.github.thought2code.mcp.annotated.server.component.completion.CompletionResult;
44
import com.github.thought2code.mcp.annotated.util.StringHelper;
55
import java.lang.annotation.ElementType;
66
import java.lang.annotation.Retention;
@@ -17,7 +17,7 @@
1717
* <p>Methods annotated with {@code @McpPromptCompletion} must:
1818
*
1919
* <ul>
20-
* <li>Return {@link McpCompleteCompletion}
20+
* <li>Return {@link CompletionResult}
2121
* <li>Accept exactly one parameter of type {@code McpSchema.CompleteRequest.CompleteArgument}
2222
* <li>Be properly configured with a prompt name
2323
* </ul>

src/main/java/com/github/thought2code/mcp/annotated/annotation/McpResourceCompletion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.thought2code.mcp.annotated.annotation;
22

3-
import com.github.thought2code.mcp.annotated.server.component.completion.McpCompleteCompletion;
3+
import com.github.thought2code.mcp.annotated.server.component.completion.CompletionResult;
44
import java.lang.annotation.ElementType;
55
import java.lang.annotation.Retention;
66
import java.lang.annotation.RetentionPolicy;
@@ -16,7 +16,7 @@
1616
* <p>Methods annotated with {@code @McpResourceCompletion} must:
1717
*
1818
* <ul>
19-
* <li>Return {@link McpCompleteCompletion}
19+
* <li>Return {@link CompletionResult}
2020
* <li>Accept exactly one parameter of type {@code McpSchema.CompleteRequest.CompleteArgument}
2121
* <li>Be properly configured with a resource URI
2222
* </ul>

src/main/java/com/github/thought2code/mcp/annotated/server/McpServerBase.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ public McpSchema.ServerCapabilities defineCapabilities() {
115115
/**
116116
* Registers all MCP server components with the specified synchronous server.
117117
*
118-
* <p>This method creates and registers the three main types of MCP components: resources,
119-
* prompts, and tools. Each component type is handled by its respective registration class which
120-
* scans for annotated methods and registers them with the server.
118+
* <p>This method creates and registers MCP components: resources, prompts, tools, and
119+
* completions. Each component type is handled by its respective registration class which loads
120+
* build-time generated definitions and registers them with the server.
121121
*
122122
* @param server the synchronous server instance to register components with
123123
*/
@@ -135,9 +135,9 @@ public void registerComponents(McpSyncServer server) {
135135
/**
136136
* Registers all MCP server components with the specified asynchronous server.
137137
*
138-
* <p>This method creates and registers the three main types of MCP components: resources,
139-
* prompts, and tools. Each component type is handled by its respective registration class which
140-
* scans for annotated methods and registers them with the server.
138+
* <p>This method creates and registers MCP components: resources, prompts, tools, and
139+
* completions. Each component type is handled by its respective registration class which loads
140+
* build-time generated definitions and registers them with the server.
141141
*
142142
* @param server the asynchronous server instance to register components with
143143
*/

src/main/java/com/github/thought2code/mcp/annotated/compiler/McpToolModelProcessor.java renamed to src/main/java/com/github/thought2code/mcp/annotated/server/component/ComponentProcessor.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.thought2code.mcp.annotated.compiler;
1+
package com.github.thought2code.mcp.annotated.server.component;
22

33
import com.github.thought2code.mcp.annotated.annotation.McpJsonSchemaDefinition;
44
import com.github.thought2code.mcp.annotated.annotation.McpJsonSchemaProperty;
@@ -9,7 +9,7 @@
99
import com.github.thought2code.mcp.annotated.annotation.McpResourceCompletion;
1010
import com.github.thought2code.mcp.annotated.annotation.McpTool;
1111
import com.github.thought2code.mcp.annotated.annotation.McpToolParam;
12-
import com.github.thought2code.mcp.annotated.server.component.completion.McpCompleteCompletion;
12+
import com.github.thought2code.mcp.annotated.server.component.completion.CompletionResult;
1313
import com.github.thought2code.mcp.annotated.util.StringHelper;
1414
import java.io.IOException;
1515
import java.io.Writer;
@@ -44,8 +44,11 @@
4444
import javax.tools.StandardLocation;
4545

4646
/**
47-
* Annotation processor that compiles {@code @McpTool} runtime reflection metadata into static model
48-
* classes.
47+
* Annotation processor that compiles MCP component annotations into static model classes at build
48+
* time.
49+
*
50+
* <p>Handles {@code @McpTool}, {@code @McpPrompt}, {@code @McpResource},
51+
* {@code @McpPromptCompletion}, and {@code @McpResourceCompletion}.
4952
*/
5053
@SupportedSourceVersion(SourceVersion.RELEASE_17)
5154
@SupportedAnnotationTypes({
@@ -55,11 +58,11 @@
5558
"com.github.thought2code.mcp.annotated.annotation.McpPromptCompletion",
5659
"com.github.thought2code.mcp.annotated.annotation.McpResourceCompletion"
5760
})
58-
public final class McpToolModelProcessor extends AbstractProcessor {
61+
public final class ComponentProcessor extends AbstractProcessor {
5962

6063
private static final String GENERATED_PACKAGE = "com.github.thought2code.mcp.annotated.generated";
6164
private static final String PROVIDER_INTERFACE =
62-
"com.github.thought2code.mcp.annotated.server.component.spi.ComponentModelProvider";
65+
"com.github.thought2code.mcp.annotated.server.component.ComponentProvider";
6366
private static final String PROVIDER_SERVICE_FILE = "META-INF/services/" + PROVIDER_INTERFACE;
6467

6568
private final List<ExecutableElement> tools = new ArrayList<>();
@@ -104,7 +107,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
104107
generated = true;
105108
} catch (IOException e) {
106109
messager.printMessage(
107-
Diagnostic.Kind.ERROR, "Failed to generate MCP tool model: " + e.getMessage());
110+
Diagnostic.Kind.ERROR, "Failed to generate MCP component model: " + e.getMessage());
108111
}
109112
return false;
110113
}
@@ -305,9 +308,9 @@ private boolean validateNoDuplicateCompletionReferences() {
305308

306309
private boolean validateCompletionSignature(ExecutableElement method) {
307310
String returnType = erasedType(method.getReturnType());
308-
if (!McpCompleteCompletion.class.getName().equals(returnType)) {
311+
if (!CompletionResult.class.getName().equals(returnType)) {
309312
messager.printMessage(
310-
Diagnostic.Kind.ERROR, "Completion method must return McpCompleteCompletion", method);
313+
Diagnostic.Kind.ERROR, "Completion method must return CompletionResult", method);
311314
return false;
312315
}
313316
if (method.getParameters().size() != 1) {
@@ -339,7 +342,7 @@ private void writeProvider() throws IOException {
339342
List<ExecutableElement> sortedCompletions =
340343
completions.stream().sorted(Comparator.comparing(this::sourceMethod)).toList();
341344
String className =
342-
"GeneratedMcpModelProvider_"
345+
"GeneratedComponentProvider_"
343346
+ Integer.toHexString(
344347
modelHash(sortedTools, sortedPrompts, sortedResources, sortedCompletions));
345348
String qualifiedName = GENERATED_PACKAGE + "." + className;
@@ -360,21 +363,21 @@ private void writeProvider() throws IOException {
360363
writer.write(
361364
"import com.github.thought2code.mcp.annotated.server.component.resource.ResourceInvoker;\n");
362365
writer.write(
363-
"import com.github.thought2code.mcp.annotated.server.component.spi.ComponentModelProvider;\n");
366+
"import com.github.thought2code.mcp.annotated.server.component.ComponentProvider;\n");
364367
writer.write(
365368
"import com.github.thought2code.mcp.annotated.server.component.tool.ToolDefinition;\n");
366369
writer.write(
367370
"import com.github.thought2code.mcp.annotated.server.component.tool.ToolInvoker;\n");
368371
writer.write("import com.github.thought2code.mcp.annotated.enums.McpServerError;\n");
369-
writer.write("import com.github.thought2code.mcp.annotated.reflect.Invocation;\n");
372+
writer.write("import com.github.thought2code.mcp.annotated.server.component.Invocation;\n");
370373
writer.write("import com.github.thought2code.mcp.annotated.util.TypeConverter;\n");
371374
writer.write("import io.modelcontextprotocol.spec.McpSchema;\n");
372375
writer.write("import java.util.ArrayList;\n");
373376
writer.write("import java.util.HashMap;\n");
374377
writer.write("import java.util.LinkedHashMap;\n");
375378
writer.write("import java.util.List;\n");
376379
writer.write("import java.util.Map;\n\n");
377-
writer.write("public final class " + className + " implements ComponentModelProvider {\n\n");
380+
writer.write("public final class " + className + " implements ComponentProvider {\n\n");
378381

379382
writer.write(" @Override\n");
380383
writer.write(" public List<ToolDefinition> tools() {\n");

src/main/java/com/github/thought2code/mcp/annotated/server/component/spi/ComponentModelProvider.java renamed to src/main/java/com/github/thought2code/mcp/annotated/server/component/ComponentProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.thought2code.mcp.annotated.server.component.spi;
1+
package com.github.thought2code.mcp.annotated.server.component;
22

33
import com.github.thought2code.mcp.annotated.server.component.completion.CompletionDefinition;
44
import com.github.thought2code.mcp.annotated.server.component.prompt.PromptDefinition;
@@ -9,9 +9,10 @@
99
/**
1010
* Service-provider entry point for build-time generated MCP models.
1111
*
12-
* <p>The initial build-time pipeline generates {@code @McpTool} metadata and invocation bindings.
12+
* <p>The build-time pipeline generates metadata and invocation bindings for tools, prompts,
13+
* resources, and completions.
1314
*/
14-
public interface ComponentModelProvider {
15+
public interface ComponentProvider {
1516
/**
1617
* Returns all component MCP tool definitions generated at build time.
1718
*

src/main/java/com/github/thought2code/mcp/annotated/reflect/Invocation.java renamed to src/main/java/com/github/thought2code/mcp/annotated/server/component/Invocation.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.thought2code.mcp.annotated.reflect;
1+
package com.github.thought2code.mcp.annotated.server.component;
22

33
import org.jetbrains.annotations.NotNull;
44

@@ -9,7 +9,7 @@
99
*/
1010
public record Invocation(@NotNull Object result, boolean isError) {
1111
/**
12-
* Returns a new instance of {@code Builder} for creating a new {@code InvocationResult}.
12+
* Returns a new instance of {@code Builder} for creating a new {@code Invocation}.
1313
*
1414
* @return a new instance of {@code Builder}
1515
*/
@@ -27,8 +27,7 @@ public String asText() {
2727
}
2828

2929
/**
30-
* This class implements the builder pattern for creating a new instance of {@code
31-
* InvocationResult}.
30+
* This class implements the builder pattern for creating a new instance of {@code Invocation}.
3231
*
3332
* @author codeboyzhou
3433
*/
@@ -63,9 +62,9 @@ public Builder isError(boolean isError) {
6362
}
6463

6564
/**
66-
* Builds a new instance of {@code InvocationResult} with the configured values.
65+
* Builds a new instance of {@code Invocation} with the configured values.
6766
*
68-
* @return a new instance of {@code InvocationResult}
67+
* @return a new instance of {@code Invocation}
6968
*/
7069
public Invocation build() {
7170
return new Invocation(result, isError);

src/main/java/com/github/thought2code/mcp/annotated/server/component/completion/CompletionInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.thought2code.mcp.annotated.server.component.completion;
22

33
import com.github.thought2code.mcp.annotated.McpApplicationContext;
4-
import com.github.thought2code.mcp.annotated.reflect.Invocation;
4+
import com.github.thought2code.mcp.annotated.server.component.Invocation;
55
import io.modelcontextprotocol.spec.McpSchema;
66

77
/** Strongly-typed invocation contract generated at build time for one completion method. */

0 commit comments

Comments
 (0)