You can connect MCP servers to your Agent to provide it with any functionality you need. The Agent will automatically utilize these tools throughout the conversation as appropriate. For an introduction to MCP, refer to the official documentation.

Connecting Your First MCP Server

To begin, you’ll need to create a server, expose its endpoint publicly, and then provide this endpoint to Neuphonic when running your Agent.

Creating Your Server

Let’s create a simple weather server. First set up your environment:
# Create a new directory for our server
mkdir weather
cd weather

# Create virtual environment and activate it
python -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install mcp requests

# Create our server file
touch weather.py
Now let’s implement the server code that defines a single tool that enables the Agent to retrieve current weather information for any location.
import requests
from mcp.server.fastmcp import FastMCP

# Initialize FastMCP server
mcp = FastMCP("weather")

# Define a single tool that allows you to get the weather
@mcp.tool()
async def get_current_weather(city: str) -> str:
    print(f"[debug-server] get_current_weather({city})")
    url = f"https://wttr.in/{city}?format=4"
    response = requests.get(url)

    if not response.ok:
        return f"Something went wrong. Unable to fetch forecast data for this city: {city}"

    print(f"[debug-server] {response.text}")
    return response.text

# Run the server on port 8000
if __name__ == "__main__":
    mcp.run(transport='sse')
Start your server by running python weather.py. You should see your server start and then remain idle (without any errors). This means your server has started successfully!

Exposing or Hosting Your Server

Now that your server is running, you’ll need to make it accessible over the Internet so that your Agent on Neuphonic’s platform can utilize the tools you’ve defined. For this demonstration, we’ll use ngrok, a service that can temporarily expose your locally running server to the Internet. Visit ngrok, create a free account (you do not need a paid tier for this walkthrough), and follow their instructions to install ngrok and authenticate your terminal to your account. This process typically takes just a couple of minutes. After setup, run the following command to expose your server:
ngrok http 8000
This will generate a URL similar to https://1234-56-789-123-4.ngrok-free.app, which serves as a public endpoint for your local MCP server. Any request to this URL will be forwarded to the MCP server running locally on your device.

Connecting Your Server to an Agent

You can now connect your MCP server to any Agent by making a small modification to the code examples from the How to Use Agents guide. Simply pass your ngrok URL to the Agent during creation, and the Agent will gain access to all tools defined in your server.
The /sse suffix in the URL below is required as it’s the default endpoint that MCP servers use to serve the tools on (via Server-Side Events). This is automatically configured by mcp.run(transport='sse').
import os
import asyncio

# See AgentConfig model for full list of parameters to configure the agent
from pyneuphonic import Neuphonic, Agent, AgentConfig

async def main():
    client = Neuphonic(api_key=os.environ.get('NEUPHONIC_API_KEY'))

    agent_id = client.agents.create(
        name='Agent 1',
        prompt='You are a helpful agent. Answer in 10 words or less.',
        greeting='Hi, how can I help you today?'
    ).data['agent_id']

    # Pass your ngrok URL into the Agent
    agent = Agent(
        client,
        agent_id=agent_id,
        mcp_servers=['https://1234-56-789-123-4.ngrok-free.app/sse']

    try:
        await agent.start()

        while True:
            await asyncio.sleep(1)
    except KeyboardInterrupt:
        await agent.stop()

asyncio.run(main())
Try running the code example above: python main.py and ask the Agent about the current weather in your city to see your MCP tools in action!