Working with MCP servers
gt4llm
comes with a simple client for Model Context Protocol (MCP) servers. Currently, only server-side capabilities (tools, prompts, and resurces) are supported.
MCP servers may connect to GT via HTTP or command line IO.
In this example, we will be using an example file server implemented by the MCP community. It assumes thagt you have npx
installed locally.
process := (GtExternalProcessBuilder new: 'npx') args: {'@modelcontextprotocol/server-filesystem'. '~'}; pipeStdin; pipeStdout; pipeStderr; spawn
Once we have a server process running, we can then make a client that connects to it.
mcpClient := GtMcpClient new transport: (GtMcpStdioTransport new process: process)
If you have an MCP server running locally, you may also connect to it using HTTP. The following example assumes a running server on the local machine on port 5000.
mcpClient := GtMcpClient new transport: (GtMcpHttpTransport new url: 'http://127.0.0.1:5000/mcp')
Once we have a connection, we can then explore Working with MCP tools, Working with MCP prompts, and Working with MCP resources.