-
Notifications
You must be signed in to change notification settings - Fork 120
mcp/examples: HTTP server example with a simple client built-in #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This fixes #165. |
@jba I think I addressed everything here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close!
examples/http/main.go
Outdated
|
||
handlerWithLogging := loggingHandler(handler) | ||
|
||
laddr := fmt.Sprintf("%s:%s", url.Hostname(), url.Port()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing proto is deceptive: I can't create an HTTPS server if I write https://example.com:8080
.
I think you should go back to host and port flags. The host will essentially always be localhost, so that should definitely be a flag. If you want to have port be an arg, I'm OK with that, but I'm also fine with a flag and a default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jba take a look -- I fixed the rest of stuff, and I want to keep the proto, because without a way to set it to https:// for the client, I can't really test the remote side, if it's behind the load balancer.
var ( | ||
host = flag.String("host", "localhost", "host to connect to/listen on") | ||
port = flag.Int("port", 8000, "port number to connect to/listen on") | ||
proto = flag.String("proto", "http", "if set, use as proto:// part of URL (ignored for server)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the server is always http, what's the point of letting the client be something different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jba The very good use case of this example is testing with real-world MCP client. In my testing, I take this code and put it on the remote VPS server behind the HTTPS load-balancer, and then I can use our client to connect to this https. And then I can use real-world client like Claude.
In other words: server is listening on 8080 HTTP but the HTTPS is provided by Caddy. And then I can test different clients with our server code
Address failing tests. |
I'm adding a practical example of an MCP with HTTP streaming: both client and server. Those are useful for testing real-world applications.