-
Notifications
You must be signed in to change notification settings - Fork 813
Support server returning only JSON on requests #299
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b37a2e1
support for server returning json -- not stream
ihrpr 71aeb9a
add examples with notifications
ihrpr 5b99e94
clean up somments
ihrpr 1aad768
Merge branch 'main' into ihrpr/response-returns-json
ihrpr a76004c
StreamableHTTPClientTransport cleanup / fixes
beaulac 632b836
remove order assumption for batch responses in test
ihrpr 77352db
Merge pull request #300 from prompteus-ai/streamable-http-client-fixes
ihrpr 962a9c9
clean up and docs fixes
ihrpr 569c928
remove promise from test
ihrpr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,34 @@ This directory contains example implementations of MCP clients and servers using | |
|
||
Multi node with stete management example will be added soon after we add support. | ||
|
||
### Server with JSON response mode (`server/jsonResponseStreamableHttp.ts`) | ||
|
||
A simple MCP server that uses the Streamable HTTP transport with JSON response mode enabled, implemented with Express. The server provides a simple `greet` tool that returns a greeting for a name. | ||
|
||
#### Running the server | ||
|
||
```bash | ||
npx tsx src/examples/server/jsonResponseStreamableHttp.ts | ||
``` | ||
|
||
The server will start on port 3000. You can test the initialization and tool calling: | ||
|
||
```bash | ||
# Initialize the server and get the session ID from headers | ||
SESSION_ID=$(curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" \ | ||
-d '{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{}},"id":"1"}' \ | ||
-i http://localhost:3000/mcp 2>&1 | grep -i "mcp-session-id" | cut -d' ' -f2 | tr -d '\r') | ||
echo "Session ID: $SESSION_ID" | ||
|
||
# Call the greet tool using the saved session ID | ||
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" \ | ||
-H "mcp-session-id: $SESSION_ID" \ | ||
-d '{"jsonrpc":"2.0","method":"mcp.call_tool","params":{"name":"greet","arguments":{"name":"World"}},"id":"2"}' \ | ||
http://localhost:3000/mcp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
``` | ||
|
||
Note that in this example, we're using plain JSON response mode by setting `Accept: application/json` header. | ||
|
||
### Server (`server/simpleStreamableHttp.ts`) | ||
|
||
A simple MCP server that uses the Streamable HTTP transport, implemented with Express. The server provides: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This doesn't work for me - I get:
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.
This worked with the current implementation: