Skip to content

core (ai/mcp): update experimental MCP client documentation for Streamable HTTP transport usage #5972

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 24 commits into from
Apr 30, 2025

Conversation

iteratetograceness
Copy link
Collaborator

@iteratetograceness iteratetograceness commented Apr 24, 2025

Background

The current experimental MCP client already supports the new HTTP transport through the custom transport option (over passing in a config).

Summary

Updates documentation to illustrate usage of the new Streamable HTTP Transport with experimental_createMCPClient for tool conversion.

As of now, experimental_createMCPClient is only used in the AI SDK as a way to fetch and call MCP server tools; for this reason, we are not adding support for Session Management or Resumable Streams - which are new features supported by the new HTTP transport.

Examples have been updated to illustrate basic usage, and a new Next.js example has been added to illustrate setting up a stateless MCP server to be used with useChat and streamText.

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Future Work

Given the deprecation of the SSE transport, we should likely deprecate on our end as well. We should consider fully deprecating native support for transports (e.g. our custom stdio transport), and enforcing users to always pass in a custom transport to limit need for maintenance on our end.

Related Issues

Fixes #5984

@iteratetograceness iteratetograceness marked this pull request as ready for review April 25, 2025 14:15
@iteratetograceness iteratetograceness changed the title chore (ai/mcp): refactor MCPClient to support HTTP transport resumability chore (ai/mcp): refactor MCPClient to support HTTP transport resumability and strictMode configuration Apr 25, 2025
@iteratetograceness iteratetograceness changed the title feat (ai/mcp): add support for sessionId and strictMode configuration to experimental MCP client feat (ai/mcp): add assertCapability method to experimental MCP client and documentation for Streamable HTTP transport usage Apr 28, 2025
@quuu
Copy link

quuu commented Apr 28, 2025

does the MCPTransport type need to be changed to either

  1. delete type: 'sse' (if the transport can be inferred from URL, don't think so?)

or

  1. add a type: 'http'

https://github.com/iteratetograceness/ai/blob/b174f68e5cb8d2d7947138534d75faf55b1729d9/packages/ai/core/tool/mcp/mcp-transport.ts#L42

@iteratetograceness
Copy link
Collaborator Author

does the MCPTransport type need to be changed to either

  1. delete type: 'sse' (if the transport can be inferred from URL, don't think so?)

or

  1. add a type: 'http'

https://github.com/iteratetograceness/ai/blob/b174f68e5cb8d2d7947138534d75faf55b1729d9/packages/ai/core/tool/mcp/mcp-transport.ts#L42

No, the experimental client accepts either a custom transport or a MCPTransportConfig (which is what you're pointing to)

@lgrammel
Copy link
Collaborator

Also consider splitting into 2 PRs? 1 for docs changes and one for assertCapability code changes (if unrelated)

@iteratetograceness iteratetograceness changed the title feat (ai/mcp): add assertCapability method to experimental MCP client and documentation for Streamable HTTP transport usage core (ai/mcp): update experimental MCP client documentation for Streamable HTTP transport usage Apr 29, 2025
iteratetograceness added a commit that referenced this pull request Apr 29, 2025
…ent (#6047)

<!--
Welcome to contributing to AI SDK! We're excited to see your changes.

We suggest you read the following contributing guide we've created
before submitting:

https://github.com/vercel/ai/blob/main/CONTRIBUTING.md
-->

## Background

Splits up #5972 into package changes
and updates to examples.

## Summary

Moves capabilities validation downstream to the request level instead of
the method level.

This PR adds a new private `assertCapability` method called at the
request level. This means our custom, lightweight client defaults strict
mode to true for tool listing and tool calling.

## Verification

<!--
For features & bugfixes.
Please explain how you *manually* verified that the change works
end-to-end as expected (independent of automated tests).
Remove the section if it's not needed (e.g. for docs).
-->

## Tasks

<!--
This task list is intended to help you keep track of what you need to
do.
Feel free to add tasks and remove unnecessary tasks as needed.

Please check if the PR fulfills the following requirements:
-->

- [x] Tests have been added / updated (for bug fixes / features)
- [ ] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added (for bug
fixes / features - run `pnpm changeset` in the project root)
- [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the
project root)

## Future Work

<!--
Feel free to mention things not covered by this PR that can be done in
future PRs.
Remove the section if it's not needed.
 -->

## Related Issues

<!--
List related issues here, e.g. "Fixes #1234".
Remove the section if it's not needed.
-->
@iteratetograceness iteratetograceness merged commit d4aa35e into vercel:main Apr 30, 2025
6 of 7 checks passed
lgrammel pushed a commit that referenced this pull request Apr 30, 2025
…ent (#6047)

<!--
Welcome to contributing to AI SDK! We're excited to see your changes.

We suggest you read the following contributing guide we've created
before submitting:

https://github.com/vercel/ai/blob/main/CONTRIBUTING.md
-->

## Background

Splits up #5972 into package changes
and updates to examples.

## Summary

Moves capabilities validation downstream to the request level instead of
the method level.

This PR adds a new private `assertCapability` method called at the
request level. This means our custom, lightweight client defaults strict
mode to true for tool listing and tool calling.

## Verification

<!--
For features & bugfixes.
Please explain how you *manually* verified that the change works
end-to-end as expected (independent of automated tests).
Remove the section if it's not needed (e.g. for docs).
-->

## Tasks

<!--
This task list is intended to help you keep track of what you need to
do.
Feel free to add tasks and remove unnecessary tasks as needed.

Please check if the PR fulfills the following requirements:
-->

- [x] Tests have been added / updated (for bug fixes / features)
- [ ] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added (for bug
fixes / features - run `pnpm changeset` in the project root)
- [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the
project root)

## Future Work

<!--
Feel free to mention things not covered by this PR that can be done in
future PRs.
Remove the section if it's not needed.
 -->

## Related Issues

<!--
List related issues here, e.g. "Fixes #1234".
Remove the section if it's not needed.
-->
lgrammel added a commit that referenced this pull request Apr 30, 2025
…ent (#6047) (#6058)

## Background

Splits up #5972 into package changes
and updates to examples.

## Summary

Moves capabilities validation downstream to the request level instead of
the method level.

This PR adds a new private `assertCapability` method called at the
request level. This means our custom, lightweight client defaults strict
mode to true for tool listing and tool calling.

Co-authored-by: Grace Yun <[email protected]>
samdenty pushed a commit that referenced this pull request May 1, 2025
…mable HTTP transport usage (#5972)

The current experimental MCP client already supports the new HTTP
transport through the custom transport option (over passing in a
config).

Updates documentation to illustrate usage of the new Streamable HTTP
Transport with `experimental_createMCPClient` for tool conversion.

As of now, `experimental_createMCPClient` is only used in the AI SDK as
a way to fetch and call MCP server tools; for this reason, we are
**not** adding support for Session Management or Resumable Streams -
which are new features supported by the new HTTP transport.

Examples have been updated to illustrate basic usage, and a new Next.js
example has been added to illustrate setting up a **stateless** MCP
**server** to be used with `useChat` and `streamText`.

<!--
This task list is intended to help you keep track of what you need to
do.
Feel free to add tasks and remove unnecessary tasks as needed.

Please check if the PR fulfills the following requirements:
-->

- [x] Tests have been added / updated (for bug fixes / features)
- [x] Documentation has been added / updated (for bug fixes / features)
- [ ] A _patch_ changeset for relevant packages has been added (for bug
fixes / features - run `pnpm changeset` in the project root)
- [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the
project root)

Given the deprecation of the SSE transport, we should likely deprecate
on our end as well. We should consider fully deprecating native support
for transports (e.g. our custom `stdio` transport), and enforcing users
to always pass in a custom transport to limit need for maintenance on
our end.

Fixes #5984
lgrammel pushed a commit that referenced this pull request May 2, 2025
…mable HTTP transport usage (#5972) (#6093)

## Background

The current experimental MCP client already supports the new HTTP
transport through the custom transport option (over passing in a
config).

## Summary

Updates documentation to illustrate usage of the new Streamable HTTP
Transport with `experimental_createMCPClient` for tool conversion.

As of now, `experimental_createMCPClient` is only used in the AI SDK as
a way to fetch and call MCP server tools; for this reason, we are
**not** adding support for Session Management or Resumable Streams -
which are new features supported by the new HTTP transport.

Examples have been updated to illustrate basic usage, and a new Next.js
example has been added to illustrate setting up a **stateless** MCP
**server** to be used with `useChat` and `streamText`.

## Future Work

Given the deprecation of the SSE transport, we should likely deprecate
on our end as well. We should consider fully deprecating native support
for transports (e.g. our custom `stdio` transport), and enforcing users
to always pass in a custom transport to limit need for maintenance on
our end.

Fixes #5984

---------

Co-authored-by: Grace Yun <[email protected]>
samdenty added a commit that referenced this pull request May 2, 2025
* origin/v5:
  fix(providers/openai): logprobs for stream alongside completion model (#6091)
  chore (ai): move maxSteps into UseChatOptions (#6113)
  docs (ai): add notes on schema .optional() (#6111)
  chore: update references to use ai-sdk.dev (#6076) (#6107)
  Version Packages (canary) (#6069)
  chore (provider-utils): rename TestServerCall.requestBody to requestBodyJson (#6106)
  chore (ai): rename CoreMessage to ModelMessage (#6105)
  feat (ai): add filename to file ui parts (#6104)
  feat (docs): add Dify community provider (#4084) (#6067) (#6103)
  feat (docs): add Sarvam community provider (#6079) (#6096)
  fix(providers/openai): zod parse error with function (#6074) (#6095)
  feat(docs): add Weave observability provider (#6029) (#6094)
  core (ai/mcp): update experimental MCP client documentation for Streamable HTTP transport usage (#5972) (#6093)
  fix (docs): update formatting in useChat reference docs  (#6100)
  chore (ai): replace useChat attachments with file ui parts (#6071)
  feat (ui/react): support resuming an ongoing stream (#6053)
  test (openai): update snapshot (#6086)
samdenty added a commit that referenced this pull request May 2, 2025
…call

* origin/v5: (43 commits)
  chore (provider-utils): return IdGenerator interface (#6118)
  chore (provider): improve jsdoc comments (#6117)
  chore (ai): remove outdated typecasts (#6116)
  chore (ai): remove useChat keepLastMessageOnError (#6114)
  fix(providers/openai): logprobs for stream alongside completion model (#6091)
  chore (ai): move maxSteps into UseChatOptions (#6113)
  docs (ai): add notes on schema .optional() (#6111)
  chore: update references to use ai-sdk.dev (#6076) (#6107)
  Version Packages (canary) (#6069)
  chore (provider-utils): rename TestServerCall.requestBody to requestBodyJson (#6106)
  chore (ai): rename CoreMessage to ModelMessage (#6105)
  feat (ai): add filename to file ui parts (#6104)
  feat (docs): add Dify community provider (#4084) (#6067) (#6103)
  feat (docs): add Sarvam community provider (#6079) (#6096)
  fix(providers/openai): zod parse error with function (#6074) (#6095)
  feat(docs): add Weave observability provider (#6029) (#6094)
  core (ai/mcp): update experimental MCP client documentation for Streamable HTTP transport usage (#5972) (#6093)
  fix (docs): update formatting in useChat reference docs  (#6100)
  chore (ai): replace useChat attachments with file ui parts (#6071)
  feat (ui/react): support resuming an ongoing stream (#6053)
  ...
iteratetograceness added a commit to iteratetograceness/ai that referenced this pull request May 9, 2025
…ent (vercel#6047) (vercel#6058)

## Background

Splits up vercel#5972 into package changes
and updates to examples.

## Summary

Moves capabilities validation downstream to the request level instead of
the method level.

This PR adds a new private `assertCapability` method called at the
request level. This means our custom, lightweight client defaults strict
mode to true for tool listing and tool calling.

Co-authored-by: Grace Yun <[email protected]>
iteratetograceness added a commit to iteratetograceness/ai that referenced this pull request May 9, 2025
…mable HTTP transport usage (vercel#5972) (vercel#6093)

The current experimental MCP client already supports the new HTTP
transport through the custom transport option (over passing in a
config).

Updates documentation to illustrate usage of the new Streamable HTTP
Transport with `experimental_createMCPClient` for tool conversion.

As of now, `experimental_createMCPClient` is only used in the AI SDK as
a way to fetch and call MCP server tools; for this reason, we are
**not** adding support for Session Management or Resumable Streams -
which are new features supported by the new HTTP transport.

Examples have been updated to illustrate basic usage, and a new Next.js
example has been added to illustrate setting up a **stateless** MCP
**server** to be used with `useChat` and `streamText`.

Given the deprecation of the SSE transport, we should likely deprecate
on our end as well. We should consider fully deprecating native support
for transports (e.g. our custom `stdio` transport), and enforcing users
to always pass in a custom transport to limit need for maintenance on
our end.

Fixes vercel#5984

---------

Co-authored-by: Grace Yun <[email protected]>
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.

Add support for Streamable HTTP mcp tools
3 participants