-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathhttp_mcp_client.py
More file actions
64 lines (47 loc) · 1.55 KB
/
http_mcp_client.py
File metadata and controls
64 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
---
title: MCP Agent
category: mcp
tags: [mcp, deepgram, openai, cartesia]
difficulty: beginner
description: Shows how to use a LiveKit Agent as an MCP client.
demonstrates:
- Connecting to a remote MCP server as a client
- Using MCP tools with voice-based interaction
---
"""
import logging
from dotenv import load_dotenv
from livekit.agents import JobContext, JobProcess, Agent, AgentSession, AgentServer, cli, mcp
from livekit.plugins import silero
load_dotenv()
logger = logging.getLogger("mcp-agent")
logger.setLevel(logging.INFO)
class MyAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions=(
"You can retrieve data via the MCP server. The interface is voice-based: "
"accept spoken user queries and respond with synthesized speech."
),
)
async def on_enter(self):
self.session.generate_reply()
server = AgentServer()
def prewarm(proc: JobProcess):
proc.userdata["vad"] = silero.VAD.load()
server.setup_fnc = prewarm
@server.rtc_session()
async def entrypoint(ctx: JobContext):
ctx.log_context_fields = {"room": ctx.room.name}
session = AgentSession(
vad=ctx.proc.userdata["vad"],
stt="deepgram/nova-3-general",
llm="openai/gpt-4.1-mini",
tts="cartesia/sonic-2:6f84f4b8-58a2-430c-8c79-688dad597532",
mcp_servers=[mcp.MCPServerHTTP(url="https://shayne.app/mcp")],
)
await session.start(agent=MyAgent(), room=ctx.room)
await ctx.connect()
if __name__ == "__main__":
cli.run_app(server)