import json import gradio as gr import os from mcp import StdioServerParameters from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient with MCPClient( {"url": "https://mdeevan-mcp-sentiment.hf.space/gradio_api/mcp/sse"} ) as tools: # Tools from the remote server are available print("\n".join(f"{t.name}: {t.description}" for t in tools)) mcp_client = MCPClient( {"url": "https://mdeevan-mcp-sentiment.hf.space/gradio_api/mcp/sse"} # This is the MCP Client we created in the previous section ) tools = mcp_client.get_tools() model = InferenceClientModel(token=os.getenv("HF_TOKEN")) agent = CodeAgent(tools=[*tools], model=model) demo = gr.ChatInterface( fn=lambda message, history: str(agent.run(message)), type="messages", examples=["today weather is nice"], title="Agent with MCP Tools", description="This is a simple agent that uses MCP tools to answer questions." ) # if __name__ == "__main__": demo.launch() # Create gradio interface # demo = gr.Interface( # fn = sentiment_analysis, # inputs = gr.Textbox(placeholder="Enter trext to analyze sentiments ..."), # outputs = gr.Textbox(), # title = "Text Sentiment Analysis", # description = "Analyze the sentiment of text using TextBlob" # ) # # Launch the interface and MCP server # demo.launch(mcp_server=True)