This guide explains how to run Model Context Protocol (MCP) servers using ToolHive. It covers how to run servers from the ToolHive registry, customize server settings, and run custom servers using Docker images or protocol schemes.
Run a server from the registryTo run an MCP server from the ToolHive registry, use the thv run
command with the name of the server you want to run. The server name is the same as its name in the registry.
For example, to run the fetch
server, which is a simple MCP server that fetches website contents:
What's happening?
When you run an MCP server from the registry, ToolHive:
toolhive: true
toolhive-name: <SERVER_NAME>
See Run a custom MCP server to run a server that is not in the registry.
Customize server settingsYou might need to customize the behavior of an MCP server, such as changing the port, mounting a local directory, or passing secrets. ToolHive provides several options to customize the server's configuration when you run it.
For a complete list of options, run thv run --help
or see the thv run
command reference.
By default, the container name matches the MCP server's name in the registry or is automatically generated from the image name when you run a custom server. To give your server instance a custom name, use the --name
option:
thv run --name <FRIENDLY_NAME> <SERVER>
For example:
thv run --name my-fetch fetch
Run a server with secrets
Many MCP servers require secrets or other configuration variables to function correctly. ToolHive lets you pass these secrets as environment variables when starting the server.
To pass a secret to an MCP server, use the --secret
option:
thv run --secret <SECRET_NAME>,target=<ENV_VAR_NAME> <SERVER>
The target
parameter specifies the name of the environment variable in the MCP server's container. This is useful for passing secrets like API tokens or other sensitive information.
For example:
thv run --secret github,target=GITHUB_PERSONAL_ACCESS_TOKEN github
See Secrets management to learn how to manage secrets in ToolHive.
Mount a local file or directoryTo enable file system access for an MCP server, you can either use the --volume
flag to mount specific paths or create a custom permission profile that defines read and write permissions.
See File system access for detailed examples.
Restrict network accessTo restrict an MCP server's network access, use the --isolate-network
flag. This enforces network access rules from either the server's default registry permissions or a custom permission profile you create.
See Network isolation for network architecture details and examples.
Add command-line argumentsSome MCP servers require additional arguments to run correctly. You can pass these arguments after the server name in the thv run
command:
thv run <SERVER> -- <ARGS>
For example:
thv run my-mcp-server:latest -- --arg1 value1 --arg2 value2
Check the MCP server's documentation for the required arguments.
Run a server on a specific portToolHive creates a reverse proxy on a random port that forwards requests to the container. This is the port that client applications connect to. To set a specific proxy port instead, use the --proxy-port
flag:
thv run --proxy-port <PORT_NUMBER> <SERVER>
Run a server exposing only selected tools
ToolHive can filter the tools returned to the client as result of a tools/list
command as well as block calls to tools that you don't want to expose.
This can help reduce the amount of tools sent to the LLM while still using the same MCP server, but it is not meant as a security feature.
To filter the list of tools, use the --tools
flag either once
thv run --tools <TOOL_1> <SERVER>
Or multiple times
thv run --tools <TOOL_1> --tools <TOOL_2> <SERVER>
For example:
thv run --tools list_issues --tools get_issue github
If the server comes from the registry, ToolHive can validate the tool names against the list advertised in the image reference. An error is returned in case ToolHive cannot find one of the specified tools.
Run a custom MCP serverTo run an MCP server that isn't in the registry, you can use a Docker image or a protocol scheme to dynamically build the server.
ToolHive supports the following transport methods:
Standard I/O (stdio
), default:
ToolHive redirects SSE or Streamable HTTP traffic from the client to the container's standard input and output. This acts as a secure proxy, ensuring that the container doesn't have direct access to the network or the host machine.
HTTP with SSE (server-sent events) (sse
):
ToolHive creates a reverse proxy that forwards requests to the container using the HTTP/SSE protocol.
Streamable HTTP (streamable-http
):
ToolHive creates a reverse proxy that forwards requests to the container using the Streamable HTTP protocol, which replaced SSE in the MCP specification as of the 2025-03-26
revision.
info
We are actively monitoring the adoption of the Streamable HTTP protocol across the client ecosystem. Once we confirm that ToolHive's supported clients support Streamable HTTP, we will make it the default proxy transport method for stdio servers.
Currently, you can add the --proxy-mode streamable-http
flag to the thv run
command to use Streamable HTTP for stdio servers. This will ensure that the server is compatible with the latest MCP specification and can be used with clients that support Streamable HTTP.
To run an MCP server from a Docker image, specify the image name and tag in the thv run
command. You can also specify a custom name for the server instance, the transport method, and any additional arguments required by the MCP server.
thv run [--name <FRIENDLY_NAME>] [--transport <stdio/sse/streamable-http>] <IMAGE_REFERENCE> -- <ARGS>
For example, to run an MCP server from a Docker image named my-mcp-server-image
that uses the Streamable HTTP transport method and takes additional arguments:
thv run --name my-mcp-server --transport streamable-http my-mcp-server-image:latest -- --arg1 value1 --arg2 value2
Check your MCP server's documentation for the required arguments.
What's happening?
When you run an MCP server from a Docker image, ToolHive:
my-mcp-server-image:latest
) and launches a container with the options and arguments you specified.--proxy-port <PORT_NUMBER>
to specify the port).toolhive: true
toolhive-name: my-mcp-server
--transport
method (stdio
, sse
, or streamable-http
).See thv run --help
for more options.
ToolHive also supports running MCP servers directly from package managers. This means you can launch MCP servers without building or publishing a Docker image, and without installing language-specific build tools on your machine.
Currently, three protocol schemes are supported:
uvx://
: For Python-based MCP servers using the uv package managernpx://
: For Node.js-based MCP servers using npmgo://
: For Go-based MCP serversthv run <uvx|npx|go>://<PACKAGE_NAME>@<VERSION|latest>
You'll likely need to specify additional arguments like the transport method, volumes, and environment variables. Check your MCP server's documentation and see thv run --help
for more options.
What's happening?
When you use a protocol scheme, ToolHive:
The uvx://
protocol is used for Python-based MCP servers. The package name must be a valid package in the PyPI registry. The @<version>
suffix is optional and defaults to the latest version if omitted.
thv run --name aws-docs uvx://awslabs.aws-documentation-mcp-server@latest
The npx://
protocol is used for Node.js-based MCP servers. The package name must be a valid package in the npm registry. The @<version>
suffix is optional and defaults to the latest version if omitted.
thv run --name pulumi npx://@pulumi/mcp-server@latest
The go://
protocol is used for Go-based MCP servers. The package name must be a valid Go module repo URI referencing the main
package. The @<version>
suffix is required.
thv run --name grafana go://github.com/grafana/mcp-grafana/cmd/mcp-grafana@latest
You can also run a local Go module by specifying the path to the module:
thv run go://./cmd/my-mcp-server
cd my-go-mcp-project
thv run go://.
thv run go:///path/to/my-go-project
Configure network transport
When you run custom MCP servers using the SSE (--transport sse
) or Streamable HTTP (--transport streamable-http
) transport method, ToolHive automatically selects a random port to expose from the container to the host and sets the MCP_PORT
and FASTMCP_PORT
environment variables in the container.
This is equivalent to running a Docker container with docker run -p <random_host_port>:<random_container_port> ...
For MCP servers that use a specific port or don't recognize those environment variables, specify the container port for ToolHive to expose using the --target-port
flag:
thv run --transport streamable-http --target-port <PORT_NUMBER> <SERVER>
ToolHive still maps the container port to a random port on the host to avoid conflicts with commonly used ports. This is equivalent to running a Docker container with docker run -p <random_port>:<PORT_NUMBER> ...
Some MCP servers use command-line arguments to specify their transport and port. For example, if your server expects the transport type as a positional argument and requires the --port
flag, you can pass it like this:
thv run --transport streamable-http --target-port <PORT_NUMBER> <SERVER> -- http --port <PORT_NUMBER>
Check your MCP server's documentation for the required transport and port configuration.
Add a custom CA certificateIn corporate environments with TLS inspection or custom certificate authorities, you may need to configure a CA certificate for ToolHive to use when building containers from protocol schemes like uvx://
, npx://
, and go://
.
ToolHive provides both global configuration and per-command options for CA certificates.
Configure a global CA certificateTo set a CA certificate that ToolHive will use for all container builds:
thv config set-ca-cert /path/to/corporate-ca.crt
To view the currently configured CA certificate:
To remove the CA certificate configuration:
Override CA certificate per commandYou can override the global CA certificate configuration for a specific run using the --ca-cert
flag:
thv run --ca-cert /path/to/other-ca.crt uvx://some-package
This is useful when you need to use different CA certificates for different servers or when testing with a specific certificate.
Priority orderToolHive uses the following priority order for CA certificates:
--ca-cert
)thv config set-ca-cert
)For example:
thv config set-ca-cert /path/to/corporate-ca.crt
thv run uvx://some-package
thv run --ca-cert /path/to/special-ca.crt uvx://other-package
Next steps
See Monitor and manage MCP servers to monitor and control your servers.
thv run
command referenceIf a server fails to start:
If a server starts but isn't accessible:
Check the server logs:
Verify the port isn't blocked by a firewall
Make sure clients are properly configured (see Client configuration)
If a server crashes or exits unexpectedly:
List all MCP servers including stopped ones:
Check the logs for error messages:
Check if the server requires any secrets or environment variables
Verify the server's configuration and arguments
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4