Skip to content

Commit 4d1d17e

Browse files
committed
fix(vefaas): mcp server in app.py
1 parent 9e8ceeb commit 4d1d17e

File tree

3 files changed

+38
-35
lines changed

3 files changed

+38
-35
lines changed

veadk/a2a/ve_a2a_server.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from veadk.a2a.agent_card import get_agent_card
2222
from veadk.a2a.ve_agent_executor import VeAgentExecutor
2323
from veadk.memory.short_term_memory import ShortTermMemory
24-
from veadk.runner import Runner
2524

2625

2726
class VeA2AServer:
@@ -49,39 +48,6 @@ def build(self) -> FastAPI:
4948
)
5049
app = app_application.build() # build routes
5150

52-
runner = Runner(
53-
agent=self.agent_executor.agent,
54-
short_term_memory=self.agent_executor.short_term_memory,
55-
app_name=self.agent_executor.app_name,
56-
user_id="",
57-
)
58-
59-
@app.post("/run_agent", operation_id="run_agent", tags=["mcp"])
60-
async def run_agent(
61-
user_input: str,
62-
user_id: str = "unknown_user",
63-
session_id: str = "unknown_session",
64-
) -> str:
65-
"""
66-
Execute agent with user input and return final output
67-
Args:
68-
user_input: User's input message
69-
user_id: User identifier
70-
session_id: Session identifier
71-
Returns:
72-
Final agent response
73-
"""
74-
# Set user_id for runner
75-
runner.user_id = user_id
76-
77-
# Running agent and get final output
78-
final_output = await runner.run(
79-
messages=user_input,
80-
session_id=session_id,
81-
)
82-
83-
return final_output
84-
8551
return app
8652

8753

veadk/cli/services/vefaas/template/deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def main():
6363
async with client:
6464
# List available tools
6565
tools = await client.list_tools()
66-
print(f"tool_0: {tools[0].__dict__}\n")
66+
print(f"tools: {tools}\n")
6767

6868
# Call run_agent tool, pass user input and session information
6969
res = await client.call_tool(

veadk/cli/services/vefaas/template/src/app.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from veadk.a2a.ve_a2a_server import init_app
1818
from veadk.tracing.base_tracer import BaseTracer
1919
from veadk.tracing.telemetry.opentelemetry_tracer import OpentelemetryTracer
20+
from veadk.runner import Runner
2021
from contextlib import asynccontextmanager
2122
from fastmcp import FastMCP
2223
from fastapi import FastAPI
@@ -72,6 +73,42 @@
7273
short_term_memory=short_term_memory,
7374
)
7475

76+
# Add a2a app to fastmcp
77+
runner = Runner(
78+
agent=agent,
79+
short_term_memory=short_term_memory,
80+
app_name=app_name,
81+
user_id="",
82+
)
83+
84+
85+
# mcp server
86+
@a2a_app.post("/run_agent", operation_id="run_agent", tags=["mcp"])
87+
async def run_agent(
88+
user_input: str,
89+
user_id: str = "unknown_user",
90+
session_id: str = "unknown_session",
91+
) -> str:
92+
"""
93+
Execute agent with user input and return final output
94+
Args:
95+
user_input: User's input message
96+
user_id: User identifier
97+
session_id: Session identifier
98+
Returns:
99+
Final agent response
100+
"""
101+
# Set user_id for runner
102+
runner.user_id = user_id
103+
104+
# Running agent and get final output
105+
final_output = await runner.run(
106+
messages=user_input,
107+
session_id=session_id,
108+
)
109+
return final_output
110+
111+
75112
mcp = FastMCP.from_fastapi(app=a2a_app, name=app_name, include_tags={"mcp"})
76113

77114
# Create MCP ASGI app

0 commit comments

Comments
 (0)