Customising tools for your hosted Patchworks MCP server

Introduction

The hosted Patchworks MCP server includes a set of default tools that are ready to use. You can't edit these, but you can add your own.

To do this, you create a draft server deployment and then write Python directly in the editor. When the draft is deployed, your custom tools become available alongside the default set.

circle-info

You need a working knowledge of Python, Pydantic, the FastMCParrow-up-right framework, and the Patchworks APIarrow-up-right to add MCP tools.

Need to know

  • Tools can only be added or updated in a draft server deployment. You can create a draft from an existing deployed server or from an inactive (i.e. previously deployed) version.

  • Any new tools must follow a defined pattern.

  • Code for built-in tools is not exposed - you cannot edit or remove default tools.

Default template

When you create a new MCP server, a default template is provided:

We break this file down in the following sections:

Import libraries

Loads required libraries, including type hints, Pydantic for argument validation, the MCP context, HTTP requests, and logging utilities.

Set up logging

Configures a logger so tools can output diagnostic messages during execution.

Built-in tools reference

A commented list of the built-in tools. This is just reference information, so you can see what's already available.

Environment

A commented summary explaining what's available in the environment (pw, get_token_from_context, decorators, etc.).

Tool pattern

A commented template showing the required three-part pattern for adding a tool: argument model, tool definition, and registry:

Use this pattern for any tools that you want to add.

Core helper

A reusable function that handles making authenticated requests to the Patchworks Core API. It reads the API base URL from the environment, attaches auth headers, makes the request, handles errors, and returns the JSON response. This helper is used by every tool.

Example tool (get all caches)

A working example (get all caches) showing the three-part pattern in practice.

Where do I add the next tool?

To extend the default specification, add your next tool right after the last. See line 138 onwards in the full example below, where we've added a tool to get connectors:

Editing an MCP server draft deployment

As noted previously, to add your own tools to the Patchworks MCP server, you must work with a draft deployment.

1

Access your MCP server deployments

Select the settings option (at the bottom of the navigation menu):

Then select the MCP servers option:

2

Create a draft deployment (if not already present)

If your server deployments list already includes a draft entry, you can skip this step. Otherwise, you can create a draft using ONE of the methods below:

If a deployed or inactive entry IS present:

chevron-rightCreate a draft from ithashtag

This creates a new draft entry, leaving any existing deployed version in place (so your AI assistant(s) can continue to access the hosted Patchworks MCP server while you make changes).

Click the ellipsis icon for the required entry:

Then select the create draft from option:

chevron-rightUndeploy the current deploymenthashtag

If a deployed entry is present, you can undeploy it. This changes the version from deployed to draft, ready for editing. However, it's important to note that your AI assistant(s) cannot access the hosted Patchworks MCP server when it is undeployed.

Click the ellipsis icon for the required entry:

Then select the undeploy option:

If a deployed or inactive entry IS NOT present:

chevron-rightCreate a new server deployment, then undeploy ithashtag

Follow instructions to deploy a hosted Patchworks MCP server for the first time, then immediately undeploy it (see above) to change the deployed status to draft).

If a deployed entry IS present, but you want to start again from scratch:

chevron-rightCreate a new server deployment, then undeploy ithashtag
  1. Follow instructions to undeploy the deployed version, setting it back to draft.

  2. Follow instructions to deploy a hosted Patchworks MCP server for the first time, then immediately undeploy it to change the deployed status to draft).

3

Edit the draft entry

Click the ellipsis icon for the draft entry, then select the edit option. For example:

4

Make required updates

Use the code editor to add/adjust tools:

5

Save or save & deploy the draft

If you want to save your changes but not deploy them yet, click the save button:

Your changes are saved and the draft status does not change.

circle-info

Keep in mind that you can't test your changes until the draft is deployed.

If you're ready to deploy the draft version, click the save and deploy button:

The draft status changes to deployed. If there was already a deployed version, this becomes inactive.

circle-info

Once your changes are deployed, you can test the updated tools via the MCP servers page and/or your AI assistant.

circle-info

Deploying an updated draft does not affect existing connections with AI assistants - these will pick up the new/changed tools when requests are made.

Last updated

Was this helpful?