Adding resources to the GT MCP server
Like tools, we can expose resources on the MCP server. We define them using a model and add them to the server.
We start a server:
server := GtLMcpServer new port: 3002; start
For the purposes of this example, we take a random page from this book:
page := LeDatabase gtBook pages atRandom. pageUri := 'lepage://' , page database properties databaseName , ':' , page title. server addResource: (GtLMcpResource new name: page title; uri: pageUri; mimeType: ZnMimeType textPlain; contentsBlock: [ GtLLepiterContentExporter new page: page; export ])
We define a client on a port matching the server:
client := GtLMcpClient new transport: (GtLMcpHttpTransport new url: 'http://localhost:3002/')
We can then query for resources:
client listResources
Or get them directly:
(client readResource: pageUri) first at: 'text'
Stop the server once you're done playing with it.
server stop