Skip to content

Conversation

@DivyaMaddipudi
Copy link

Issue #, if available:

Description of changes:

This commit adds support for native remote MCP servers with the following key changes:

  • Proxies are now started immediately but initialized only after receiving an actual initialize request
  • startProxies() starts proxy connections while initializeProxies() handles the MCP protocol initialization
  • Uses proxiesInitialized flag to prevent duplicate initialization

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines +37 to +39
this.client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(30))
.build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the smithy-java ClientTransport, not the Java HttpClient directly.

throw new IllegalArgumentException("JsonRpcRequest cannot be null");
}
String body = JSON_CODEC.serializeToString(request);
LOG.debug("Sending HTTP request to {}", endpoint);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be trace at the minimum.

.connectTimeout(Duration.ofSeconds(30))
.build();
this.endpoint = URI.create(builder.url);
this.name = builder.name != null ? builder.name : "HTTP-" + endpoint.getHost();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MCP server names have restrictions on what characters they can have. I don't think we can put the whole URI in here.


public Builder headers(Map<String, String> headers) {
this.headers = headers;
return this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is assuming a static set of headers can be provided at initialization time which is wrong. Headers specially Auth Headers change over time and with requestbased on things like Session expiry, credentials refresh etc.

Comment on lines +229 to +237
boolean supportsOutputSchema = supportsOutputSchema(protocolVersion);
List<ToolInfo> filteredTools = tools.values()
.stream()
.filter(tool -> toolFilter.allowTool(tool.serverId(), tool.toolInfo().getName()))
.map(tool -> extractToolInfo(tool, supportsOutputSchema))
.toList();

return createSuccessResponse(req.getId(),
ListToolsResult.builder().tools(filteredTools).build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Comment on lines +171 to +178
// Initialize proxies lazily after we have a real initialize request
if (!proxiesInitialized) {
initializeProxies(response -> {
// Proxies are initialized, no additional response needed
});
proxiesInitialized = true;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

public void startProxies() {
for (McpServerProxy proxy : proxies.values()) {
proxy.start();
proxy.initialize(responseWriter, initializeRequest.get());
Copy link
Author

@DivyaMaddipudi DivyaMaddipudi Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initializeRequest.get() is giving me an NPE because we don't have any JSON-RPC request when the proxy starts. We need to either manually pass a JSON-RPC request to initialize the call or perform the initialization. For example:

https://github.com/smithy-lang/smithy-java/pull/943/files#diff-98c1d22a8180d3700e143f1b567faab2c3d3bdfac31593242af08bf77ce1d616R171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants