Commit graph typescript-sdk/src/client
Author SHA1 Message Date
Daniel Leal
d38a5979ac Add request init headers defined on the sse transport to the start 2025-05-22 19:11:23 +01:00
Jeff Escalante
0516f9898b
add state param to oauth provider (#529) 2025-05-22 12:55:00 +01:00
Frédéric Barthelet
281cf0bf8d
Save existing refresh_token in store if no new refresh_token is returned (#483)
As described in https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-12#name-refresh-token-response,
server MAY return a new refresh_token. In case it doesn't, current implementation discard initial refresh
token if it was still valid.
2025-05-21 17:29:56 +01:00
Itsuki
69dbfac0e4
Feat: Separate authorization server and resource server on client auth flow (#416)
* add type and schema for protected resource metadata

* add private variable to keep track of
authorization server url to avoid fetching Protected Resource Metadata every time

* change auth flow to use authroization server and
add function to discover protected resource metadata

* add/modify tests for new added auth functions

* modify test to use the authorization server

* remove unused variable

* add resource parameter when building auth url

* Change resource to use the protected resource metadata

* resolve typo.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* Update src/client/sse.ts import.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove log.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* Update section title.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove log.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove resource parameter.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove resource parameter.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove resource parameter.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove resource parameter.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove resource parameter.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove resource parameter.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove resource parameter.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove resource parameter.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* remove resource parameter.

Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>

* make backwards compatibile

* s/resourceServerUrl/serverUrl/g for backwards compat

* fix test comment

---------

Co-authored-by: itsuki <itsuki.enjyoy@gmail.com>
Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>
Co-authored-by: Paul Carleton <paulc@anthropic.com>
2025-05-21 14:55:38 +01:00
Basil Hosmer
4cc8ed43b4
Fix Ajv import compatibility issue by downgrading to v6
Downgrade Ajv from v8.17.1 to v6.12.6 to resolve ESM/CJS module compatibility issues that were causing "does not provide an export named 'Ajv'" errors in projects using this SDK. This ensures consistent import patterns across different module systems.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-19 13:05:21 -04:00
Basil Hosmer
82f5f70924
rollback path preservation fix 2025-05-16 17:45:44 -04:00
Basil Hosmer
00cb9203cd
fix sse endpoint path preservation 2025-05-16 16:48:31 -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
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
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
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
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
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
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
ihrpr
5dba9477ff
small fixes after suggested changes 2025-04-17 17:34:15 +01:00
ihrpr
c053c2e97d
handle session termination 2025-04-16 11:56:28 +01:00
ihrpr
585dc06708
introduce onsessioninitialized to avoid race conditions 2025-04-16 11:09:47 +01:00
ihrpr
31f44e0b68
add isInitializeRequest and isInitializedNotification utility 2025-04-16 10:19:46 +01:00
ihrpr
8bc49f9f34
change names to resumptionToken instead of last event id 2025-04-15 22:06:10 +01:00
ihrpr
f1c5ef1a8d
apply suggested changes 2025-04-15 20:40:26 +01:00
ihrpr
f1e6acb17d
resumed tool to return value 2025-04-15 16:37:31 +01:00
ihrpr
54d6929149
don't need to re-initialize when we reconnect a session 2025-04-15 11:58:43 +01:00
ihrpr
1359e9fe6a
pull transport send options into own named type 2025-04-15 11:42:16 +01:00
ihrpr
621e65c42b
Merge branch 'resumability' into ihrpr/resume-long-running-requests 2025-04-15 11:14:39 +01:00
ihrpr
67a4595ae7
improve event store interface 2025-04-15 11:03:44 +01:00
ihrpr
583202f81a
address client comments 2025-04-15 09:24:11 +01:00
ihrpr
7aeb67988a
improve comments 2025-04-14 09:37:19 +01:00
ihrpr
43cb015844
resume long running requst from new client 2025-04-13 21:40:15 +01:00
ihrpr
6374f43390
limit on retries 2025-04-13 15:18:52 +01:00
ihrpr
64fadf3cf2
resume streams on error - initial implementation 2025-04-13 08:26:49 +01:00
ihrpr
18e4981bd3
move get sse stream from a separate method to automatic connection when notifications/initialized received 2025-04-11 14:06:51 +01:00
ihrpr
5c5a33021c
add GET to examples servers 2025-04-10 15:28:39 +01:00
Antoine Beauvais-Lacasse
a76004c92b StreamableHTTPClientTransport cleanup / fixes
* always send headers specified in requestInit option
* avoid doubled onerror call
* use for-await to iterate SSE stream
* remove outdated comments
* simplify requestId tracking
* throw error when response Content-Type is out of spec
2025-04-09 21:18:50 -04:00
ihrpr
26929fa9b7
fix lint 2025-04-09 11:17:34 +01:00
ihrpr
18674007e5
remove the _activeStreams map 2025-04-09 11:13:28 +01:00
ihrpr
1d18a57a17
extract standalone get into a method which can be called by a client 2025-04-09 09:50:59 +01:00
ihrpr
15c10a5883
fix lint 2025-04-08 22:30:15 +01:00
ihrpr
d4ad976401
use EventSourceParserStream 2025-04-08 21:39:49 +01:00
ihrpr
f1827ced10
handle not implemented get 2025-04-08 15:04:07 +01:00
ihrpr
c3b446d424
multiple streams and initial stream with get 2025-04-08 11:11:09 +01:00