Sub topic 14
Sharing and deploying the server for your team
This chapter assumes you have a working server from the earlier chapters, with tools, typed schemas, and tested behavior in the MCP Inspector. You should also be comfortable with Python packaging basics, Docker, and environment variables. The goal here is to get the server off your laptop and into your teammates' hands without making it fragile or unsafe.
Choose a distribution model first
A server on your machine works for you. Your team needs it to be installable, versioned, and updatable. There are three common models, and the right one depends on the transport you chose earlier.
| Model | Transport | How teammates get it | Best when |
|---|---|---|---|
| Shared repository | stdio | Clone the repo, create a virtual environment, point the host at the script | Two or three people, rapid iteration |
| Installable package | stdio | Run a pinned version with `uvx` or `pipx` | Tools are stateless and use each person's own credentials |
| Hosted service | Streamable HTTP | Add a URL to the host configuration | Shared state, central credentials, or tools that need network access teammates lack |
With stdio, the host starts your server as a subprocess on each person's machine. The server runs with that person's permissions and network access. With Streamable HTTP, one process serves many clients, so you must handle authentication, concurrency, and uptime yourself.
Package the server
An installable package gives every teammate the same code and gives you a version number to talk about. Use a src layout and expose a console script as the entry point.
[project]
name = "team-tools-mcp"
version = "0.3.0"
requires-python = ">=3.10"
dependencies = ["mcp>=1.2,<2"]
[project.scripts]
team-tools-mcp = "team_tools.server:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
packages = ["src/team_tools"]Upper-bound the mcp dependency. The SDK evolves, and an unplanned major upgrade on a teammate's machine is a hard bug to diagnose.
Next, make the entry point choose its transport from the environment. One codebase can then run as a local stdio server or a hosted HTTP service.
# src/team_tools/server.py
import logging
import os
import sys
from mcp.server.fastmcp import FastMCP
# stdout carries protocol messages under stdio, so log to stderr.
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
logger = logging.getLogger("team-tools")
mcp = FastMCP(
"team-tools",
host=os.environ.get("MCP_HOST", "127.0.0.1"),
port=int(os.environ.get("MCP_PORT", "8000")),
)
OWNERS = {"billing": "payments-team", "search": "discovery-team"}
@mcp.tool()
def get_service_owner(service: str) -> str:
"""Return the team that owns a service, given its short name."""
if service not in OWNERS:
raise ValueError(f"Unknown service: {service}")
return OWNERS[service]
def main() -> None:
transport = os.environ.get("MCP_TRANSPORT", "stdio")
logger.info("Starting team-tools with transport=%s", transport)
mcp.run(transport=transport)
if __name__ == "__main__":
main()The default host is 127.0.0.1. A server that listens only on the loopback interface cannot be reached from other machines, which is the safe default for anything you run locally.
Run a pinned version over stdio
Once the package lives in an internal Git repository or package index, teammates run it with uvx. Pin a tag so a new commit does not change behavior under them.
{
"mcpServers": {
"team-tools": {
"command": "uvx",
"args": [
"--from",
"git+https://git.example.com/platform/[email protected]",
"team-tools-mcp"
],
"env": {
"TEAM_API_TOKEN": "set-in-your-own-environment"
}
}
}
}Commit this file as a template, not with real tokens. Each person supplies their own credentials, so the server acts with that person's access and audit logs show the right user. File locations and exact keys vary by host, so link to each host's documentation in your README.
To upgrade, change the tag in the configuration and restart the host. Hosts generally read the server list at startup, so a restart is part of every rollout.
Host it over Streamable HTTP
Choose a hosted service when the tools need a service account, a private network that laptops cannot reach, or state shared across users. Package it in a container:
FROM python:3.12-slim
WORKDIR /app
COPY pyproject.toml ./
COPY src ./src
RUN pip install --no-cache-dir .
ENV MCP_TRANSPORT=streamable-http \
MCP_HOST=0.0.0.0 \
MCP_PORT=8000
EXPOSE 8000
USER nobody
CMD ["team-tools-mcp"]Build and run it locally to check the endpoint:
docker build -t team-tools-mcp:0.3.0 .
docker run --rm -p 8000:8000 -e TEAM_API_TOKEN="$TEAM_API_TOKEN" team-tools-mcp:0.3.0
npx @modelcontextprotocol/inspectorIn the Inspector, choose the Streamable HTTP transport and enter http://localhost:8000/mcp. The Python SDK serves the endpoint at /mcp by default. Listing tools and calling one confirms that the container works before any host is involved.
Setting MCP_HOST=0.0.0.0 makes the server reachable from outside the container. Inside a container this is required, because the published port is forwarded to the container's network interface. It also means you must decide who can reach that port.
Authentication for a hosted server
The MCP specification defines an OAuth 2.1 based authorization flow for HTTP transports. Support in hosts and in the SDK is still maturing, so check what your hosts implement. Practical options, from simplest to most capable:
- Put the server behind your existing gateway or identity-aware proxy. The proxy authenticates users with single sign-on and forwards only valid requests.
- Require a bearer token per user, issued and revocable by you, and validate it on every request.
- Implement the full MCP authorization flow once your hosts support it.
Whichever you choose, terminate TLS at the proxy or load balancer, and validate the Origin header on requests if browsers can reach the server. This prevents a malicious web page from calling a service bound to a local or internal address.
Authentication tells you who is calling. Your tools still need to check what that user may do. A single shared service account behind the server can quietly give every teammate the access of its most privileged tool, so scope the account's permissions to the minimum the tools need, and log the caller's identity with each tool call.
Stateless versus stateful sessions
By default, Streamable HTTP sessions keep state in the server process. That is a problem when you run several replicas behind a load balancer, because a follow-up request can land on a replica that has no record of the session. You have two choices. Either enable sticky routing, or run the SDK in stateless mode by passing stateless_http=True to FastMCP. Stateless mode works for tools that do not depend on server-initiated messages such as progress streams or sampling requests. If your tools are plain request-and-response calls to internal APIs, stateless is usually the simpler option to scale.
Operate it like any other service
A shared server becomes infrastructure. Treat it that way.
- Configuration: read secrets from environment variables or your secret manager. Do not bake them into the image or commit them.
- Logging: write structured logs with the tool name, caller identity, duration, and outcome. Never log full argument values if they may contain secrets or personal data.
- Timeouts: give every outbound call a timeout shorter than the host's tool timeout. A tool that hangs makes the model's whole turn hang.
- Rate limits: limit calls per user. A model in a loop can call a tool hundreds of times.
- Health checks: expose a simple check for your orchestrator, separate from the MCP endpoint.
- Resource limits: set CPU and memory limits on the container so one runaway tool cannot starve the node.
Version tool changes carefully
Tool names and schemas form a contract with the model and with any prompts your teammates wrote around them. Treat changes like API changes.
| Change | Risk | Approach |
|---|---|---|
| Add an optional parameter | Low | Ship in a minor version |
| Add a new tool | Low | Ship in a minor version, and check that the description does not overlap an existing tool |
| Rename a tool or parameter | High | Keep the old name for one release, mark it deprecated in its description, then remove it |
| Change a result's shape | High | Add a new tool or a versioned field instead of changing the existing one |
| Remove a tool | High | Announce it, and remove it in a major version |
Keep a changelog, tag every release, and run the Inspector against a release candidate before you move the tag teammates use.
Rollout checklist
- Pin the dependency range and the release tag.
- Document the install steps in the README, including the host configuration template.
- Verify the server in the Inspector against the packaged build, not your working directory.
- Confirm that credentials are per user for stdio and authenticated for HTTP.
- Start with a small group, watch the logs for tool errors, and then expand.
Exercise
Your team has twelve engineers. The server's tools call an internal API that only a service account can reach, and the API is not reachable from laptops. Which distribution model fits, and what must you add before sharing the URL?
Show answer
Use a hosted service over Streamable HTTP, because the service account and network access must live on the server, not on each laptop. Before sharing the URL, add authentication (for example an identity-aware proxy or per-user bearer tokens) and TLS, scope the service account to the minimum the tools need, and log the caller's identity on each tool call. Origin validation, timeouts, and rate limits are also needed.
Exercise
A teammate renames the parameter service to service_name in a tool and tags a release. Several teammates' saved prompts stop working. What should the release process have done instead?
Show answer
A parameter rename is a breaking change. The release should have accepted both names for at least one release, noted the deprecation in the tool description and changelog, and removed the old name only in a later major version after announcing it. Running the Inspector against the release candidate would also have shown the changed schema before the tag moved.