Skip to main content
What you’ll build: A minimal but complete FastMCP setup — a Python server that exposes tools, and a SambaCloud-powered client that lets a model discover and call them.

Overview

FastMCP is a high-level Python framework for building Model Context Protocol clients and servers with minimal boilerplate. Whether you’re developing tools that interact with language models or integrating external APIs over MCP, FastMCP cuts the ceremony with clean Python syntax and a small, focused API. This guide walks you through integrating FastMCP with SambaCloud so you can:

Enable tool use

Let SambaCloud models call your Python functions through the OpenAI-compatible function-calling interface.

Orchestrate agents

Build multi-agent systems where models pick the right tool at the right time.

Bridge external APIs

Wrap any third-party service as an MCP tool and make it model-callable.

Serve custom agents

Ship lightweight, decorator-based handlers with zero framework overhead.

Prerequisites

  • A SambaCloud account and API key from the SambaCloud portal
  • Python 3.10 or later installed. Confirm with python --version.
  • Familiarity with Python virtual environments and terminal basics

Installation

1

Create and activate a virtual environment

2

Install the required packages

openai is used to call SambaCloud’s OpenAI-compatible API. The mcp package provides both the FastMCP server class and the MCP client utilities — no extra dependencies needed.
3

Export your SambaCloud API key

Never commit your API key to source control. Use a .env file or your shell’s secret manager.

Usage

A working FastMCP + SambaCloud setup has two pieces:
1

An MCP server

Exposes Python functions as tools.
2

A client

Calls SambaCloud, lets the model decide which tool to invoke, and routes that call back to the server.

1. Define an MCP server

Save the following as example_server.py. The @mcp.tool() decorator exposes each function over MCP, and mcp.run(transport="stdio") makes the server reachable through stdio.
example_server.py
@mcp.tool() exposes a function as a callable MCP tool. You can register multiple tools and handle complex inputs using standard Python type annotations — FastMCP generates the JSON schema for you.

2. Call SambaCloud and route tool calls back to the server

The client points the OpenAI SDK at SambaCloud’s base URL, launches example_server.py as a stdio subprocess, and forwards any tool calls the model returns.
client.py
For the full, runnable bridge — including the MCP-to-OpenAI tool-schema conversion and the response-handling loop — see the MCP SambaNova examples notebook.

Use cases

Function calling

Enable tool use and function calling with any SambaCloud-hosted model.

Multi-agent orchestration

Build agent frameworks that compose tools and delegate across specialists.

External API integration

Expose REST, GraphQL, or internal services as model-callable tools.

Lightweight custom agents

Ship decorator-based handlers without heavyweight framework lock-in.

Resources

MCP SambaNova examples

End-to-end notebook with the full client bridge.

FastMCP documentation

Official FastMCP framework reference.

MCP Python SDK

Low-level Model Context Protocol SDK.

Supported models

Models available on SambaCloud for tool use.

Troubleshooting

  • Run pip install --upgrade mcp to ensure you have a recent version
  • Confirm your virtual environment is active: which python should point inside .venv
  • FastMCP moved into the official mcp package — do not install the separate fastmcp package
  • Confirm the key is exported: echo $SAMBANOVA_API_KEY
  • Re-export with export SAMBANOVA_API_KEY="your-key" and retry
  • The client reads it via os.environ["SAMBANOVA_API_KEY"] — the variable must be set in the same shell session
  • Ensure each tool function has a docstring — FastMCP uses it to generate the JSON schema the model sees
  • Verify provider={"only": ["sambanova"]} or equivalent routing is set in the client call
  • Check the model supports function calling on the SambaCloud models page
  • mcp requires Python 3.10 or later — confirm with python --version
  • If using an older version, create a new virtual environment with Python 3.10+