-
Notifications
You must be signed in to change notification settings - Fork 1.6k
MCPClient streamable_http transport support #2030
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8fcef56
added streamablehttp support, bumped mcp version, added additional he…
yousifa c720cfc
updated streamablehttp to use StreamableHttpParameters type
yousifa 4956886
updated error message with StreamableHttpParameters
yousifa 1cac028
example using http transport for mcp client
yousifa f0bcc9d
Add MCPClient docstrings. Removed google specific cleanup, changed ex…
markbackman 46b52cb
Merge branch 'main' into mcp-streaming-http
yousifa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # | ||
| # Copyright (c) 2024–2025, Daily | ||
| # | ||
| # SPDX-License-Identifier: BSD 2-Clause License | ||
| # | ||
|
|
||
| import argparse | ||
| import os | ||
|
|
||
| from dotenv import load_dotenv | ||
| from loguru import logger | ||
| from mcp.client.session_group import StreamableHttpParameters | ||
|
|
||
| from pipecat.audio.vad.silero import SileroVADAnalyzer | ||
| from pipecat.pipeline.pipeline import Pipeline | ||
| from pipecat.pipeline.runner import PipelineRunner | ||
| from pipecat.pipeline.task import PipelineParams, PipelineTask | ||
| from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext | ||
| from pipecat.services.openai.llm import OpenAILLMService | ||
| from pipecat.services.cartesia.tts import CartesiaTTSService | ||
| from pipecat.services.deepgram.stt import DeepgramSTTService | ||
| from pipecat.services.mcp_service import MCPClient | ||
| from pipecat.transports.base_transport import BaseTransport, TransportParams | ||
| from pipecat.transports.network.fastapi_websocket import FastAPIWebsocketParams | ||
| from pipecat.transports.services.daily import DailyParams | ||
|
|
||
| load_dotenv(override=True) | ||
|
|
||
| # We store functions so objects (e.g. SileroVADAnalyzer) don't get | ||
| # instantiated. The function will be called when the desired transport gets | ||
| # selected. | ||
| transport_params = { | ||
| "daily": lambda: DailyParams( | ||
| audio_in_enabled=True, | ||
| audio_out_enabled=True, | ||
| vad_analyzer=SileroVADAnalyzer(), | ||
| ), | ||
| "twilio": lambda: FastAPIWebsocketParams( | ||
| audio_in_enabled=True, | ||
| audio_out_enabled=True, | ||
| vad_analyzer=SileroVADAnalyzer(), | ||
| ), | ||
| "webrtc": lambda: TransportParams( | ||
| audio_in_enabled=True, | ||
| audio_out_enabled=True, | ||
| vad_analyzer=SileroVADAnalyzer(), | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| async def run_example(transport: BaseTransport, _: argparse.Namespace, handle_sigint: bool): | ||
| logger.info(f"Starting bot") | ||
|
|
||
| stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY")) | ||
|
|
||
| tts = CartesiaTTSService( | ||
| api_key=os.getenv("CARTESIA_API_KEY"), | ||
| voice_id="71a7ad14-091c-4e8e-a314-022ece01c121", # British Reading Lady | ||
| ) | ||
|
|
||
| llm = OpenAILLMService( | ||
| api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4o-mini" | ||
| ) | ||
|
|
||
| try: | ||
| # Github MCP docs: https://github.com/github/github-mcp-server | ||
| # Enable Github Copilot on your GitHub account. Free tier is ok. (https://github.com/settings/copilot) | ||
| # Generate a personal access token. It must be a Fine-grained token, classic tokens are not supported. (https://github.com/settings/personal-access-tokens) | ||
| # Set permissions you want to use (eg. "all repositories", "profile: read/write", etc) | ||
| mcp = MCPClient( | ||
| server_params=StreamableHttpParameters( | ||
| url="https://api.githubcopilot.com/mcp/", | ||
| headers={"Authorization": f"Bearer {os.getenv('GITHUB_PERSONAL_ACCESS_TOKEN')}"}, | ||
| ) | ||
| ) | ||
| except Exception as e: | ||
| logger.error(f"error setting up mcp") | ||
| logger.exception("error trace:") | ||
|
|
||
| tools = await mcp.register_tools(llm) | ||
|
|
||
| system = f""" | ||
| You are a helpful LLM in a WebRTC call. | ||
| Your goal is to answer questions about the user's GitHub repositories and account. | ||
| You have access to a number of tools provided by Github. Use any and all tools to help users. | ||
| Your output will be converted to audio so don't include special characters in your answers. | ||
| Don't overexplain what you are doing. | ||
| Just respond with short sentences when you are carrying out tool calls. | ||
| """ | ||
|
|
||
| messages = [{"role": "system", "content": system}] | ||
|
|
||
| context = OpenAILLMContext(messages, tools) | ||
| context_aggregator = llm.create_context_aggregator(context) | ||
|
|
||
| pipeline = Pipeline( | ||
| [ | ||
| transport.input(), # Transport user input | ||
| stt, | ||
| context_aggregator.user(), # User spoken responses | ||
| llm, # LLM | ||
| tts, # TTS | ||
| transport.output(), # Transport bot output | ||
| context_aggregator.assistant(), # Assistant spoken responses and tool context | ||
| ] | ||
| ) | ||
|
|
||
| task = PipelineTask( | ||
| pipeline, | ||
| params=PipelineParams( | ||
| enable_metrics=True, | ||
| enable_usage_metrics=True, | ||
| ), | ||
| ) | ||
|
|
||
| @transport.event_handler("on_client_connected") | ||
| async def on_client_connected(transport, client): | ||
| logger.info(f"Client connected: {client}") | ||
| # Kick off the conversation. | ||
| await task.queue_frames([context_aggregator.user().get_context_frame()]) | ||
|
|
||
| @transport.event_handler("on_client_disconnected") | ||
| async def on_client_disconnected(transport, client): | ||
| logger.info(f"Client disconnected") | ||
| await task.cancel() | ||
|
|
||
| runner = PipelineRunner(handle_sigint=handle_sigint) | ||
|
|
||
| await runner.run(task) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| from pipecat.examples.run import main | ||
|
|
||
| main(run_example, transport_params=transport_params) | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.