Enables integration with Databricks Genie Spaces, allowing tools to query and interact with Databricks catalogs, schemas, and tables through authenticated workspace clients. Supports both service principal and user-level authentication for accessing Databricks resources.
MCP StoneX UDP Genie
A simple, production-ready template for building Model Context Protocol (MCP) servers using FastMCP and FastAPI. This project demonstrates how to create custom tools that AI assistants can discover and invoke.
š Quickstart Setup Guide
Follow these steps to deploy and connect your MCP StoneX UDP Genie App:
0. Update the Repository
Add or update tools as needed.
Note: You currently need to define a separate tool for each Genie.
1. Launch as a Databricks App
Run the following commands in your project directory:
2. Assign App Permissions
For the auto-created App Service Principal, grant ALL of the following permissions in Databricks:
CAN USEon the AppCAN RUNon the Genie SpaceUSE CATALOGon the Genie Space's catalog targetUSE SCHEMAon the Genie Space's schema targetSELECTon all tables in the Genie Space's schema target
3. Create a Databricks App Connection
Go to Databricks Account Console
Go to Settings ā App Connections.
Click Add Connection.
Set up as follows:
REDIRECT_URL:
{databricks_app_url}/.auth/callbackCLIENT_SECRET:
YES (copy & save for step 4)OAUTH_ACCESS_SCOPE:
all-apis
4. Configure an External UC Connection
Fill in the following values:
Field | Value |
CONNECTION_TYPE |
|
AUTH_TYPE |
|
HOST |
|
CLIENT_ID | (from previous step) |
CLIENT_SECRET | (from previous step) |
OAUTH_SCOPE |
|
TOKEN_ENDPOINT |
|
BASE_PATH |
|
IS_MCP_CONNECTION |
|
5. Add to Playground or Supervisor
Register the External MCP Server in Playground or Multi-agent Supervisor for testing and multi-agent experiments.
Key Concepts
Tools: Callable functions that AI assistants can invoke (e.g., search databases, process data, call APIs)
Server: Exposes tools via the MCP protocol over HTTP
Client: Applications (like Claude, AI assistants) that discover and call tools
Features
ā FastMCP-based server with HTTP streaming support
ā FastAPI integration for additional REST endpoints
ā Example tools: health check and user information
ā Production-ready project structure
ā Ready for Databricks Apps deployment
Project Structure
Prerequisites
Python 3.11 or higher
uv (recommended) or pip
Installation
Option 1: Using uv (Recommended)
Option 2: Using pip
Running the Server
Development Mode
The server will start on http://localhost:8000 by default (or your specified port).
Accessing the Server
MCP Endpoints:
http://localhost:8000/mcpAvailable Tools:
health: Check server statusget_current_user: Get authenticated user information
Testing the MCP Server
This project includes test scripts to verify your MCP server is working correctly in both local and deployed environments.
Integration Tests
The project includes automated integration tests that validate the MCP server functionality:
What the tests do:
Automatically start the MCP server
Test that
list_tools()works correctlyTest that all registered tools can be called without errors by invoking the
call_tools()Automatically clean up the server after tests complete
Manual Testing
End-to-end test your locally-running MCP server
The script connects to your local MCP server without authentication and lists available tools.
End-to-end test your deployed MCP server
After deploying to Databricks Apps, use the interactive shell script to test with user-level OAuth authentication:
The script will guide you through:
Profile selection: Choose your Databricks CLI profile
App name: Enter your deployed app name
Automatic configuration: Extracts app scopes and URLs automatically
OAuth flow: Generates user OAuth token via browser
End-to-end test: Tests
list_tools(), and invokes each tool returned in list_tools
What it does:
Retrieves app configuration using
databricks apps getExtracts user authorization scopes from
effective_user_api_scopesGets workspace host from your Databricks profile
Generates OAuth token with the correct scopes
Tests MCP client with user-level authentication
Verifies both the
healthcheck andget_current_usertool work correctly
This test simulates the real end-user experience when they authorize your app and use it with their credentials.
Alternatively, test manually with command-line arguments:
The scripts/dev/query_remote.py script connects to your deployed MCP server with OAuth authentication and tests both the health check and user authorization functionality.
Adding New Tools
To add a new tool to your MCP server:
Open
server/tools.pyAdd a new function inside
load_tools()with the@mcp_server.tooldecorator:
Restart the server - the new tool will be automatically available to clients
Tool Best Practices
Clear naming: Use descriptive, action-oriented names
Comprehensive docstrings: AI uses these to understand when to call your tool
Type hints: Help with validation and documentation
Structured returns: Return dicts or Pydantic models for consistent data
Error handling: Use try-except blocks and return error information
Connecting to Databricks
The utils.py module provides two helper methods for interacting with Databricks resources via the Databricks SDK Workspace Client:
When deployed as a Databricks App:
get_workspace_client()- Returns a client authenticated as the service principal associated with the app. See App Authorization for more details.get_user_authenticated_workspace_client()- Returns a client authenticated as the end user with scopes specified by the app creator. See User Authorization for more details.
When running locally:
Both methods return a client authenticated as the current developer, since no service principal identity exists in the local environment.
Example usage in tools:
See the get_current_user tool in server/tools.py for a complete example.
Generating OAuth Tokens
For advanced use cases, you can manually generate OAuth tokens for Databricks workspace access using the provided script. This implements the OAuth U2M (User-to-Machine) flow.
Generate Workspace-Level OAuth Token
Parameters:
--host: Databricks workspace URL (required)--scopes: Space-separated OAuth scopes (default:all-apis offline_access)--redirect-uri: Callback URI (default:http://localhost:8020)
Note: The script uses the databricks-cli OAuth client ID by default.
The script will:
Generate a PKCE code verifier and challenge
Open your browser for authorization
Capture the authorization code via local HTTP server
Exchange the code for an access token
Display the token response as JSON (token is valid for 1 hour)
Example with custom scopes:
Configuration
Server Settings
The server can be configured using command-line arguments:
The default configuration:
Host:
0.0.0.0(listens on all network interfaces)Port:
8000(configurable via--portargument)
Deployment
Databricks Apps
This project is configured for Databricks Apps deployment:
Deploy using Databricks CLI or UI
The server will be accessible at your Databricks app URL
For more information refer to the documentation here
Try Your MCP Server in AI Playground
After deploying your MCP server to Databricks Apps, you can test it interactively in the Databricks AI Playground:
Navigate to the AI Playground in your Databricks workspace
Select a model with the Tools enabled label
Click Tools > + Add tool and select your deployed MCP server
Start chatting with the AI agent - it will automatically call your MCP server's tools as needed
The AI Playground provides a visual interface to prototype and test your MCP server with different models and configurations before integrating it into production applications.
For more information, see Prototype tool-calling agents in AI Playground.
Development
Code Formatting
Customization
Rename the Project
Update
nameinpyproject.tomlUpdate
nameparameter inserver/app.py:FastMCP(name="your-name")Update the command script in
pyproject.tomlunder[project.scripts]
Add Custom API Endpoints
Add routes to the app FastAPI instance in server/app.py:
Troubleshooting
Port Already in Use
Change the port in server/main.py or set the PORT environment variable.
Import Errors
Ensure all dependencies are installed:
Resources
AI Assistant Context
See Claude.md for detailed project context specifically designed for AI assistants working with this codebase.