MCPKit - Create MCP servers for LLMs with Xojo

I’m pleased to announce MCPKit, an open source module for Xojo for creating MCP servers with Xojo: GitHub repo.

What is a MCP server?

A Model Context Protocol (MCP) server is an application that exposes tools to a large language model (LLM) over a standardised protocol. The MCP protocol was created by Anthropic, is well documented and is supported by the major proprietary LLM vendors as well as open source solutions such as LM Studio.

About MCPKit

MCPKit is a Xojo module that contains everything you need to turn a Xojo ConsoleApplication into a MCP server. Simply drop the module into a Xojo console project, change the superclass of the App object to MCPKit.ServerApplication and you’re good to go.

The module supports command line options and custom tools. For a more thorough implementation, see my mcpweb GitHub project which provides Kagi-based web searching for local LLMs:

MCPKit server application lifecycle

The MCPKit.ServerApplication exposes three event definitions:

  • WillParseOptions
  • DidParseOptions
  • Configure

You don’t need to implement the Run event as the server will start up immediately and process incoming responses automatically.

If you want to specify command line arguments for your server then define them in WillParseOptions like so:

// Add a single required option for an API key to be passed to the server.
Self.CommandLineParser.AddOption("k", "apikey", "The API key to use.", _
MCPKit.OptionTypes.String, True)

As soon as the command line arguments have been parsed, the DidParseOptions event is raised so you can grab their values in this event through the application’s CommandLineParser object. They are available elsewhere in your app but it’s not until the DidParseOptions event has been raised that they have been validated.

If required options are not passed to the application or there is another error then the server will log this to stderr and correctly report back via MCP to the calling LLM that a problem occurred.

Once command line options have been parsed but before the server actually starts running, the Configure event is raised. Use this event to register any tools that you’d like to expose to LLMs. Tools can take any number of named parameters and pass these to a tool’s Run method. Write your Xojo code in this method and return a response to the LLM in the form of a string.

If you check out my mcpweb project you’ll see a class named KagiSearchTool that’s a subclass of MCPKit.Tool and illustrates how easy it is to expose parameters to an LLM, describe the tool and then execute Xojo code and return the response. In fact, not counting the web searching code in the KagiSearchTool class, there’s only 6 lines of Xojo code to get a MCP server up and running in the mcpweb project!

16 Likes

Neat! Should the link to mcpweb work?

Oops, fixed. The repo was private but I’ve changed it to public:

6 Likes

:star_struck::open_mouth: :scream:

:collision:

1 Like

Just a little explanation of how to use my example MCP server mcpweb (taken from the updated README in it’s repo).

Usage

Build the project and place the built components in the desired location on your system. I’m on a Mac and I place it in my Users folder: /Users/garry/mcp-servers/mcpweb.

In your MCP client application (e.g. LM Studio, Claude Desktop, etc), follow the instructions on how to add an MCP server to the application. This usually involves editing some sort of mcp.json file.

mcpweb currently only supports searching the web using Kagi and so it requires an --apikey command line argument containing a valid API key for Kagi. This requires a subscription but in my opinion is worth it.

You can also pass a --verbose flag to mcpweb which will instruct it to output detailed logging to stderr.

Here is what my LM Studio mcp.json file looks like (API key redacted):

{
  "mcpServers": {
    "mcpweb": {
      "command": "/Users/garry/mcp-servers/mcpweb/mcpweb",
      "args": [
        "--apikey",
        "YOUR_API_KEY_HERE"
      ]
    }
  }
}

Once you’ve informed your MCP client about the server, you normally have to restart the client to finalise things. Once that’s done, you’re local LLM will use mcpweb to search the web using Kagi.

Hopefully looking at the code will demonstrate how easy it is to build your own tools to use with LLMs using Xojo.

3 Likes

finally found a moment to test it, when first run it says

i click resolve, when i run the project it says

and thanks for putting the spot on Kagi , looked at it sems great, why nobody is talking about it much ?

That’s a Xojo compiler bug - it’s too stupid to recognise that there is a class called Search and a method called Search. I’ve renamed the method to PerformSearch and pushed a new version to GitHub. It should work without complaining now.

2 Likes

Update: mcpweb is now mcpkagi

Just a little note (since I can’t edit my earlier posts) that mcpweb has been renamed to mcpkagi to better reflect that it only searches the web using the Kagi search engine.

The usage is the same.

The repo is: https://github.com/gkjpettet/mcpkagi.

so mind sharing your workflow ,organisation beetween all those MCP servers you made ? did you receive mac ultra, do you store web content locally ?

thanks again for the great work :slight_smile: