Update mcp_server
Browse files- mcp_server +10 -12
mcp_server
CHANGED
|
@@ -3,27 +3,25 @@ from mcp import StdioServerParameters
|
|
| 3 |
from smolagents import MCPClient, CodeAgent
|
| 4 |
|
| 5 |
|
| 6 |
-
def respond(
|
| 7 |
-
"""Send the
|
| 8 |
-
# Launch the MCP server as a subprocess (stdio transport)
|
| 9 |
params = StdioServerParameters(command="python", args=["mcp_server.py"])
|
| 10 |
with MCPClient(params) as tools:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
history.append((prompt, result))
|
| 15 |
return history, history
|
| 16 |
|
| 17 |
|
| 18 |
with gr.Blocks() as demo:
|
| 19 |
-
|
| 20 |
-
|
| 21 |
chatbot = gr.Chatbot(label="Enterprise SQL Agent")
|
| 22 |
-
|
|
|
|
| 23 |
show_label=False,
|
| 24 |
-
placeholder="Ask
|
| 25 |
)
|
| 26 |
-
|
| 27 |
|
| 28 |
gr.Markdown(
|
| 29 |
"""
|
|
|
|
| 3 |
from smolagents import MCPClient, CodeAgent
|
| 4 |
|
| 5 |
|
| 6 |
+
def respond(message, history):
|
| 7 |
+
"""Send the message to the MCP‑powered agent and return its reply."""
|
|
|
|
| 8 |
params = StdioServerParameters(command="python", args=["mcp_server.py"])
|
| 9 |
with MCPClient(params) as tools:
|
| 10 |
+
agent = CodeAgent(tools=tools, model="gpt-4") # replace with your model or OpenAI wrapper
|
| 11 |
+
answer = agent.run(message)
|
| 12 |
+
history.append((message, answer))
|
|
|
|
| 13 |
return history, history
|
| 14 |
|
| 15 |
|
| 16 |
with gr.Blocks() as demo:
|
| 17 |
+
state = gr.State([])
|
|
|
|
| 18 |
chatbot = gr.Chatbot(label="Enterprise SQL Agent")
|
| 19 |
+
|
| 20 |
+
textbox = gr.Textbox(
|
| 21 |
show_label=False,
|
| 22 |
+
placeholder="Ask: Who are my inactive Northeast customers?",
|
| 23 |
)
|
| 24 |
+
textbox.submit(respond, [textbox, state], [chatbot, state])
|
| 25 |
|
| 26 |
gr.Markdown(
|
| 27 |
"""
|