Skip to content

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

wkoszek
Copy link
Contributor

@wkoszek wkoszek commented Jul 23, 2025

I'm adding a practical example of an MCP with HTTP streaming: both client and server. Those are useful for testing real-world applications.

@wkoszek wkoszek changed the title mcp examples: HTTP server example with a simple client built-in mcp/examples: HTTP server example with a simple client built-in Jul 23, 2025
@jba
Copy link
Contributor

jba commented Jul 25, 2025

This fixes #165.

@wkoszek
Copy link
Contributor Author

wkoszek commented Jul 26, 2025

@jba I think I addressed everything here.

Copy link
Contributor

@jba jba left a comment

Choose a reason for hiding this comment

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

Close!


handlerWithLogging := loggingHandler(handler)

laddr := fmt.Sprintf("%s:%s", url.Hostname(), url.Port())
Copy link
Contributor

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.

Copy link
Contributor Author

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)")
Copy link
Contributor

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?

Copy link
Contributor Author

@wkoszek wkoszek Jul 30, 2025

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

jba
jba previously approved these changes Aug 4, 2025
@jba
Copy link
Contributor

jba commented Aug 4, 2025

Address failing tests.

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