Commit graph typescript-sdk/src
Author SHA1 Message Date
Basil Hosmer
39b2f65434
restore server-side validation for tools returning structuredContent without outputSchema
Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-15 10:03:50 -04:00
Basil Hosmer
6b680ca18a
Move testOutputSchemaServers.ts to client examples directory
This file is a client implementation that tests outputSchema servers,
so it belongs in the client examples directory rather than server examples.
Updated file paths in error messages to reflect the new location.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-15 10:03:50 -04:00
Basil Hosmer
712b04e96d
Refactor McpServer tool registration API
- Remove tool() overload that takes a config object with callback
- Add new registerTool() method that separates config from callback
- Extract common tool registration logic into _createRegisteredTool() helper
- Update all tests to use registerTool() for tools with output schemas
- Update examples to use registerTool() and high-level Client API
- Add comment noting that output schema validation only works with high-level API

This change improves API clarity by using a distinct method for tools with
output schemas while maintaining backward compatibility.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-15 10:03:50 -04:00
Basil Hosmer
eb0407ea40
split comment for readability 2025-05-15 10:03:50 -04:00
Basil Hosmer
18c7e795a0
address comments: 1. validate schemas w/o codegen, 2. relax no-structured-output restriction 2025-05-15 10:03:50 -04:00
Basil Hosmer
0fa3277550
avoid ({}) => ... in tests 2025-05-15 10:03:50 -04:00
Basil Hosmer
e1abdab7f5
update examples, update package-lock.json 2025-05-15 10:03:48 -04:00
Basil Hosmer
6079cd8307
- add new tool() api and tests
- fix schema validation
- comment headers on tests
2025-05-15 10:03:02 -04:00
Basil Hosmer
9686fc2ead
formatting, more version rollbacks 2025-05-15 10:02:03 -04:00
Basil Hosmer
27d66ef031
back out protocol version change 2025-05-15 10:02:02 -04:00
Basil Hosmer
bb28098d81
feat: add server-side support for tool outputSchema with backward compatibility
- Update McpServer to support registering tools with outputSchema
- Add automatic content generation from structuredContent for backward compatibility
- Add validation to ensure proper usage of structuredContent vs content
- Add comprehensive tests for outputSchema functionality
- Add example servers demonstrating structured output usage
- Update existing test to match new backward compatibility behavior

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-15 10:02:02 -04:00
Basil Hosmer
882e0b7d05
feat: update TypeScript SDK to implement draft spec changes for structured tool output
- Add outputSchema support to Tool interface with proper documentation
- Split CallToolResult into structured and unstructured variants
- Change structuredContent from string to object type
- Add validation that tools without outputSchema cannot return structuredContent
- Add validation that tools with outputSchema must return structuredContent
- Update client to validate structured content as object (no JSON parsing)
- Update tests to use object format for structuredContent
- Add tests for new validation constraints
- Update LATEST_PROTOCOL_VERSION to DRAFT-2025-v2

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-15 10:02:02 -04:00
Basil Hosmer
cf12fe0d83
Add client-side validation for tool output schemas
- Cache tool output schemas when listing tools
- Validate structuredContent against outputSchema during callTool
- Enforce that tools with outputSchema must return structuredContent
- Add json-schema-to-zod dependency for schema conversion
- Add comprehensive tests for validation scenarios

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-15 10:01:58 -04:00
Basil Hosmer
a85fee407a
Add support for outputSchema and optional content fields in tools
- Add outputSchema field to Tool type and RegisteredTool interface
- Make content field optional in CallToolResult
- Update ListToolsRequestSchema handler to include outputSchema in tool list responses
- Add support for structuredContent in tool results
- Update examples to handle optional content field
- Add tests for new outputSchema and structuredContent functionality
- Update ToolCallback documentation to clarify when to use structuredContent vs content

This change enables tools to define structured output schemas and return
structured JSON content, providing better type safety and validation for
tool outputs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-15 09:58:40 -04:00
Xiao Yijun
66dec56467
feat(auth): support custom scope in authorization requests (#491)
* feat(auth): support custom scope in authorization requests

* fix(auth): default to provider's scope if not provided
2025-05-14 18:45:18 +01:00
ihrpr
bac916e804
Merge pull request #399 from its-nikhil/FEAT-auth-ctx-streamable-http
[FEAT] added support for AuthInfo in extra for StreamableHTTPServerTransport
2025-05-14 14:30:28 +01:00
olaservo
2f522bf370
Add failing tests 2025-05-12 11:25:41 -04:00
Basil Hosmer
5a25fe3a6c
fix: preserve custom paths in SSE endpoint URLs
When an SSE client connects with a custom path (e.g., /api/v1/custom/sse),
ensure the endpoint URL maintains the same base path structure but with
/messages instead of /sse. This fixes issues where custom endpoints were
getting collapsed to the root path.

Should fix issues reported in modelcontextprotocol/inspector#313 and #296
Tests demonstrating the issue were added in PR #439

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-12 11:09:12 -04:00
bhosmer-ant
bced33d8bc
Merge pull request #468 from geelen/fix-tool-annotation-confusion
Fix Zod object detection logic
2025-05-09 18:01:38 -04:00
Basil Hosmer
4a295a4043
remove vendored library tests 2025-05-09 17:48:33 -04:00
Basil Hosmer
3c9496812e
tweak heuristic type test for isZodRawShape
- simpler test for empty object
- only test public zod properties (parse, safeParse)

Confirmed that vendored-library tests still pass. Note that you need the --testPathIgnorePatterns to avoid the __tests__ directory (this is what was breaking the build):
$ npm test -- --testPathIgnorePatterns="vendor"
2025-05-09 17:43:00 -04:00
ihrpr
bf7fd4470e
Merge pull request #464 from pcarleton/pcarleton/oauth-scope
feat: Add scope parameter to startAuthorization function
2025-05-09 11:40:37 +01:00
Glen Maddern
b6617dc44c Fix Zod object detection logic
Previously, this check was `value instanceof ZodType`, which breaks if
the user is using a different version of Zod than the library. Instead,
do the check using the structure of the input object rather than its
prototype chain.

Additionally, this adds a vendored version of Zod to use for tests, which
ensures that regressions like this would be caught next time.
2025-05-09 15:26:33 +10:00
yuna0x0
52dc7f1160
Fix isZodRawShape return false on empty object and add test 2025-05-06 01:49:33 +08:00
Paul Carleton
30b5544e8b feat: Add scope parameter to startAuthorization function
- Add optional scope parameter to startAuthorization function signature
- Include scope in authorization URL query parameters when provided
- Update auth function to pass through scope from provider.clientMetadata
- Add tests to verify scope is correctly included/excluded from auth URL

This enhancement allows clients to specify authorization scopes during the OAuth flow.
2025-05-02 08:40:58 +00:00
Henry Wildermuth
def417f2df Add stderr access before start 2025-04-30 16:46:35 -07:00
cliffhall
d11673fc2d Add client/server version negotiation tests without mocks
* In src/client/index.test.ts added tests:
  - "should connect new client to old, supported server version"
  - should negotiate version when client is old, and newer server supports its version"
  - "should throw when client is old, and server doesn't support its version"
2025-04-28 18:01:24 -04:00
Cliff Hall
f2f030e479
Merge branch 'main' into update-protocol-version 2025-04-28 17:59:36 -04:00
cliffhall
cada5a4266 Add client/server version negotiation tests without mocks
* In src/client/index.test.ts added tests:
  - "should connect new client to old, supported server version"
  - should negotiate version when client is old, and newer server supports its version"
  - "should throw when client is old, and server doesn't support its version"
2025-04-28 17:58:47 -04:00
ihrpr
7e18c70169
Merge pull request #403 from botengyao/fix-comments-stateless
comment: fix stateless comments that no session-id is included in any responses
2025-04-28 18:39:31 +01:00
ihrpr
dbd439ec57
Merge pull request #406 from botengyao/format-issue
nit: fix the comment format in the streamableHTTP.ts
2025-04-28 18:31:14 +01:00
ihrpr
465ba67194
Merge pull request #409 from mhart/patch-1
Ensure JSONRPCError messages are sent for streamable http
2025-04-28 18:26:57 +01:00
ihrpr
89f7fb7a10
Merge pull request #411 from fredericbarthelet/add-unauthorized-error-test
Add 401 during POST request test case on StreamableHTTP transport to check auth flow
2025-04-28 18:15:48 +01:00
Frédéric Barthelet
eb486d5cbc Add auth flow on 401 during POST request test case on StreamableHTTP transport 2025-04-25 16:27:58 +02:00
cliffhall
84dc914231 Update protocol version
* tidy types.test.ts
2025-04-25 09:29:29 -04:00
cliffhall
1e9d5d548a Update protocol version
* Added types.test.ts
  - "should have correct latest protocol version"
  - "should have correct supported protocol versions"
2025-04-25 09:28:16 -04:00
cliffhall
3a9a6c944b Update protocol version
* This fixes #378
* In types.ts
  - set LATEST_PROTOCOL_VERSION to "2025-03-26"
  - add "2025-03-26" to SUPPORTED_PROTOCOL_VERSIONS
* In auth.test.ts
  - in test "returns metadata when discovery succeeds"
    - expect "MCP-Protocol-Version" to be "2025-03-26"
2025-04-25 09:16:28 -04:00
Marcel Samyn
75eb1c431a Pass request _meta to request handlers extra param 2025-04-25 14:42:59 +02:00
Michael Hart
67ad0bd773
Ensure JSONRPCError messages are sent for streamable http
Prior to this, any JSONRPCError message sent when `enableJsonResponse` is true would be ignored (and response.end() never called)
2025-04-25 22:18:18 +10:00
Boteng Yao
868fc7b432 fix format 2025-04-25 03:43:05 +00:00
Boteng Yao
414cb11898 fix stateless comments 2025-04-25 01:42:36 +00:00
Nikhil Taneja
4b5c16fae0 [FEAT] added unit test for StreamableHTTPServerTransport with AuthInfo 2025-04-24 23:26:21 +05:30
Nikhil Taneja
37ca02d36d [FEAT] added support for AuthInfo in extra for StreamableHTTPServerTransport 2025-04-24 19:22:55 +05:30
ihrpr
9db5b8363c
fix sse examples 2025-04-23 22:32:56 +01:00
ihrpr
3f95b76dcf
Merge pull request #338 from TomasRup/fix-example-in-stateless
stateless had a wrong example
2025-04-23 22:30:36 +01:00
Basil Hosmer
e53608ea19
rebase and address comments 2025-04-22 16:37:16 -04:00
Basil Hosmer
c5e81adcd8
Fix example to properly position tool annotations 2025-04-22 15:24:38 -04:00
Basil Hosmer
0096be432f
Add ToolAnnotations support to McpServer.tool() method 2025-04-22 15:24:32 -04:00
ihrpr
f41769184d
Merge pull request #358 from lforst/lforst-pass-request-id-to-extra
Pass `requestId` to handlers via metadata
2025-04-22 18:17:26 +01:00
Tomas Petras Rupšys
d61e59defe
Update src/server/streamableHttp.ts
Co-authored-by: ihrpr <inna.hrpr@gmail.com>
2025-04-22 14:20:08 +03:00