mgbam commited on
Commit
d2c5450
·
verified ·
1 Parent(s): ba3687a

Update mcp_server

Browse files
Files changed (1) hide show
  1. 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(prompt, history=[]):
7
- """Send the user prompt to the MCP‑powered agent and return the reply."""
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
- # Replace "gpt-4" with your preferred local or API‑based LLM
12
- agent = CodeAgent(tools=tools, model="gpt-4")
13
- result = agent.run(prompt)
14
- history.append((prompt, result))
15
  return history, history
16
 
17
 
18
  with gr.Blocks() as demo:
19
- chat_history = gr.State([])
20
-
21
  chatbot = gr.Chatbot(label="Enterprise SQL Agent")
22
- prompt_box = gr.Textbox(
 
23
  show_label=False,
24
- placeholder="Ask questions like: 'Who are my inactive Northeast customers?'",
25
  )
26
- prompt_box.submit(respond, [prompt_box, chat_history], [chatbot, chat_history])
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
  """