user-robot-xmarksRunning an Agent Locally using GLChat MCP Server

This is an example of how to run an agent that leverages GLChat MCP tools locally.

circle-exclamation
chevron-rightPrerequisiteshashtag

This example specifically requires:

Running The Code

circle-info

All the code used in the following examples can be found in our GitHub repository gen-ai-examples/custom-tool-and-agentarrow-up-right.

git clone https://github.com/GDP-ADMIN/gen-ai-examples.git
cd gen-ai-examples/examples/custom-tool-and-agent

Set up your OPENAI_API_KEY

circle-info

  • Environment Variable Option

    export OPENAI_API_KEY="sk-..."

  • Environment File (.env) Option

    echo 'OPENAI_API_KEY="sk-..."' > .env

Execute the script

​The script will do the following:

  1. Spawn a GLChat MCP Server that has a messagetool.

chevron-rightShow me some code.hashtag
  1. Create an agent with an MCP Client connecting to the GLChat MCP Server.

chevron-rightShow me some code.hashtag
  1. Execute query What is the capital of Indonesia?.

chevron-rightShow me some code.hashtag

With verbose=True, you will see the agent's thinking process, which may look like this:

Available tools: ['message'] Running agent with prompt: What is the capital of Indonesia? > Entering new AgentExecutor chain... Invoking: `message` with `{'prompt': 'What is the capital of Indonesia?'}`

Processing request of type CallToolRequest The capital of Indonesia is Jakarta. The capital of Indonesia is Jakarta. > Finished chain. {'input': 'What is the capital of Indonesia?', 'output': 'The capital of Indonesia is Jakarta.'}

The key indicators of success:

  • The agent initialization completes without errors

  • The verbose output shows the tool being invoked

  • The final output shows {'input': 'What is the capital of Indonesia?', 'output': 'The capital of Indonesia is Jakarta.'}

Customizing MCP Servers

In the mcp_configs/configs.pyarrow-up-right file, you can customize the MCP servers. You can add or remove MCP Servers as per your requirements.

Defining an MCP Server requires the transport to be defined. It is one of:

  • stdio

  • sse

circle-exclamation

STDIO Server

An STDIO server is a server that uses the standard input and output to communicate with the MCP.

command can be one of (but not limited to):

  • python

  • npx

  • docker

args is a list of arguments to pass to the command.

SSE Servers

An SSE server is a server that uses the Server-Sent Events (SSE) to communicate with the MCP. It simply needs a URL to the SSE endpoint. Typically, this ends in /sse.

Example

An example of multiple MCP servers is as follows:

Last updated