Working with GT as an MCP server

GT ships with a minimal implementation of an MCP server that can execute tools.

N.B.: This server was neither hardened nor audited. It is a simple Zinc server that might crash or, depending on the capabilities you give the tools it exposes, do undesirable things to your image or system at large. Use with caution at this time.

To start an MCP server on port 3000, execute the following snippet.

server := GtMcpServer new
		port: 3000;
		start
  

To stop the server, you can call GtMcpServer>>#stop stop server ifNotNil: [ server stop. server := nil ] on it.

server stop
  

Once we have a server, we can add tools to it. The tools use the same model as in Adding custom tools to assistants and can thus be shared across assistants and servers.

server
	addTool: (GtLlmFunctionTool new
			name: 'getImplementors';
			parameters: {'methodName'};
			description: 'Gets a method by name and returns a list of methods that implement it.';
			block: [ :functionCall | 
				Character cr
					join: (functionCall anyArgument asSymbol gtImplementors result toArray wait
							collect: #name) ])
  

Once we have this server, we can test it by connecting to it using a client.

client := GtMcpClient new
	transport: (GtMcpHttpTransport new url: 'http://localhost:3000/')
  

We can confirm the presence of the tools, either through navigating to the view on the client, or programmatically.

client listTools
  

Once we’ve confirmed the presence of the tool, we can call it.

client
	callTool: 'getImplementors'
	withArguments: {'methodName' -> 'callTool:withArguments:'} asDictionary