Astra MCP Server
Project description
Agentic Astra
A Model Context Protocol (MCP) server for interacting with Astra DB (DataStax Astra).
The agentic-astra that provides tools to interact with Astra DB. It is built with FastMCP and Astrapy (then Astra DB or DataStax HCD can be used as database).
The server will load the tool definitions from a collection in Astra DB or a file. The tool definitions are then transformed to a function definition that can be passed to an LLM, making it possible to use the tools provided by the MCP Server in an Agentic workflow.
When a tool is called, the server will call the appropriate method in Astra DB or DataStax HCD, converting the parameters to the appropriate filters and return the result to the MCP Client/Agent. If some embedding generations is required, the models from OpenAI or IBM Watsonx can be used for similarity search.
How to run the Astra MCP Server
Running it as MCP Server with STDIO
To run the agentic-astra as MCP Server with STDIO, you can use the following command:
uvx agentic-astra --astra_token <astra_token> --astra_endpoint <astra_endpoint>
Running it as MCP Server with Langflow
To access the tools provided by agentic-astra as MCP Server with Langflow, you can add an MCP Server with the following configuration:
After adding the MCP Server, you can connect it to an Agent component:
The tool names and descriptions are loaded from the catalog collection in Astra DB.
Running it as MCP Server with IBM Orchestrate
To access the tools provided by agentic-astra as MCP Server with IBM Orchestrate, you can add an MCP Server with the following configuration:
Running it as MCP Server with HTTP locally
To run the agentic-astra as MCP Server with STDIO, you can use the following command:
uvx agentic-astra -tr http
If you have an .env file, the varriables will be considered while running the server. Otherwise, you can pass arguments to the server. Check the App options below for more details.
App options
--transport <transport>: The transport to use for the MCP Server. Valid values arestdioandhttp. Default isstdio.--astra_token <astra_token>: The Astra token to use for the Astra DB connection. If not filled, the app will try to get the token from theASTRA_DB_APPLICATION_TOKENenvironment variable.--astra_endpoint <astra_endpoint>: The Astra endpoint to use for the Astra DB connection. If not filled, the app will try to get the endpoint from theASTRA_DB_API_ENDPOINTenvironment variable.--tags <tags>: The tags to filter the tools for the MCP Server.
Catalog options
--catalog_file <catalog_file>: The catalog file to use for the MCP Server. Default istools_config.json. If not filled, the app will try to get the catalog from theASTRA_DB_CATALOG_COLLECTIONenvironment variable.--catalog_collection <catalog_collection>: The catalog collection to use for the MCP Server. Default istool_catalog. If not filled, the app will try to get the catalog from theASTRA_DB_CATALOG_COLLECTIONenvironment variable.
Options valid for the HTTP transport:
When running the app as HTTP, you can use the following options:
--host <host>: The host to use for the MCP Server. Default is127.0.0.1.--port <port>: The port to use for the MCP Server. Default is8000.--workers <workers>: The number of worker processes to use for the MCP Server. Default is1.--log-level <log_level>: The log level to use for the MCP Server. Valid values aredebug,info,warning, anderror. Default isinfo.--log-file <log_file>: The log file to use for the MCP Server. Default islogs/agentic_astra.log.--audit <audit>: Whether to enable audit trail. Default isfalse.
1. Set up environment variables
If you are running the app with some MCP Client that allows you to define environment variables, you can set the same variables in the MCP Client.
If you prefer, you can create a .env file in app directory with the following variables:
# Astra DB Configuration
ASTRA_DB_APPLICATION_TOKEN=your_astra_db_token
ASTRA_DB_API_ENDPOINT=your_astra_db_endpoint
ASTRA_DB_CATALOG_COLLECTION=tool_catalog
LOG_LEVEL=DEBUG
LOG_FILE=./logs/logs.log
# Logging Configuration (optional)
LOG_LEVEL=INFO
LOG_FILE=logs/agentic_astra.log
#Embedding and Agentic Tool Generation Configuration
OPENAI_API_KEY=your_openai_api_key
OPENAI_BASE_URL=your_openai_base_url
IBM_WATSONX_API_KEY=your_ibm_watsonx_api_key
IBM_WATSONX_BASE_URL=your_ibm_watsonx_base_url
IBM_WATSONX_PROJECT_ID=your_ibm_watsonx_project_id
#Audit Trail Configuration
ASTRA_DB_AUDIT_TABLE_NAME=mcp_audit_trail
#Authorization Configuration
AGENTIC_ASTRA_TOKEN=your_agentic_astra_token
# Legacy support (optional):
# ASTRA_MCP_SERVER_TOKEN=your_agentic_astra_token
The Tool Catalog
The tool catalog is the collection of tools that the MCP Server will provide to the MCP Clients/Agents. It can be save to a file or to a Astra DB collection (preferable for production use cases).
Check the examples in the examples/tools directory for more details.
The tools are created based on a json specification that needs the following fields:
{
"tags": ["products"], // The tags of the tool - Filter if needed
"type": "tool", // The type of the tool
"name": "search_products", // The name of the tool
"description": "Search for products", // The description of the tool to the MCP Client
"limit": 10, // The limit of the tool
"method": "find_documents", // The method to use to execute the tool
"collection_name": "products", // The collection to use to execute the tool
"table_name": "products", // The table to use to execute the tool (if the collection_name is not filled)
"projection": {"$vectorize": 1, "metadata": 0}, // The projection of the tool
"parameters": [ // The parameters of the tool
{
"param": "search_query", // The name of the parameter
"description": "Query to search for products", // The description of the parameter
"attribute": "$vectorize", // The attribute of the parameter... or $vectorize
"type": "string", // The type of the parameter
"required": 1, // Whether the parameter is required
"operator": "$eq", // The operator to use to filter the parameter - if not filled, the operator is $eq
"expr": "date(departure_time) > date('today')", // The expression to use to filter the parameter - if not filled, the expression is not applied
"enum": ["baggage", "boarding", "check-in", "flight-status", "other"], // The enum of the parameter
"embedding_model": "text-embedding-3-small", // The embedding model to use to generate the embedding
"info": "indexed column" // The information about the parameter - indexed column, partition key, sorting key, vector column, etc.
},
{
"param": "in_stock", // The name of the parameter
"value": true, // The value of the parameter - IF FILLED, THE PARAMETER IS NOT SENT TO THE MCP CLIENT and applied by the server
"attribute": "in_stock" // The attribute of the parameter
}
],
}
Save the json document to the file or to the Astra DB collection. When the server is started, it will load the tools from the file or the Astra DB collection.
After storing on Astra DB, the tools will appear in the Astra DB collection like this:
Updating tools
To update the tools, you can update the json document and save it to the file or to the Astra DB collection.
# Upload a catalog file to Astra DB
uv run agentic-astra-catalog -f tools_config_example.json -t tool_catalog
# Upload with custom table name
uv run agentic-astra-catalog -f my_tools.json -t my_tool_catalog
# Get help
uv run agentic-astra-catalog --help
Agentic Tool Generation
The agentic-astra includes a tool specification generator that can automatically create tool configurations by analyzing your Astra DB tables. This is particularly useful when you have existing data and want to quickly generate MCP tools for it.
Prerequisites
- Set the
ASTRA_DB_APPLICATION_TOKENenvironment variable - Set the
OPENAI_API_KEYenvironment variable - Access to the Astra DB database and table you want to analyze
Usage
# Generate tool specification for a table
uv run agentic-astra-tool-agent --table-name <table_name> --keyspace-name <keyspace_name> --db-name <db_name> --out-file <json file name> -ai "tool should be used only for future flights, so add a parameter for departure date > today" -pf <prompt file path> -ep <export prompt file path>
Command Options
--export-prompt/-ep: Export the prompt used to generate the tool specification--table-name/-t: Name of the table to analyze (required)--collection-name/-c: Name of the collection to analyze (required)--keyspace-name/-k: Name of the keyspace to analyze (default:default_keyspace)--db-name/-d: Name of the database containing the table (required)--out-file/-o: Output file path for the generated JSON (required) - If not filled, the tool specification will be printed to the console--sample-size/-s: Number of sample records to analyze (default: 5)--additional-instructions/-ai: Additional instructions for the tool specification generation--prompt-file/-pf: Prompt file to use for the tool specification generation
What it does
- Connects to Astra DB using your existing credentials
- Retrieves table schema and analyzes the structure
- Samples data (first 5 records by default) to understand field types
- Generates parameters automatically based on actual table fields
- Creates tool specification in the exact format required by the MCP server
- Outputs JSON ready to use with your MCP server
### Integration with Existing Workflow
After generating a tool specification, you can:
1. **Review and customize** the generated JSON as needed
2. **Upload to Astra DB** using the catalog tool:
```bash
uv run agentic-astra-catalog -f user_tool.json -t tool_catalog
Local Development
# Install dependencies
uv sync
# Run the server
uv run agentic-astra --host 127.0.0.1 --port 5150 --reload --log-level debug
Alternative: Direct uvicorn (for development)
# Run directly with uvicorn
uv run uvicorn server:main --factory --reload --port 5150 --log-level debug
Using MCP Inspector (STDIO)
npx @modelcontextprotocol/inspector uv run agentic-astra --log-level debug -tr stdio
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentic_astra-0.0.5.tar.gz.
File metadata
- Download URL: agentic_astra-0.0.5.tar.gz
- Upload date:
- Size: 554.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b43fbeaa8ac357ab90d3e725a711b6620881b624befd3bf6c8d5113ced7ea929
|
|
| MD5 |
73446dda2825465d26d730e49a93e41d
|
|
| BLAKE2b-256 |
176e507cafa0c1c44e23bbf9cd88444d19964d2ebeaf919b8c3dc7f7234f03af
|
File details
Details for the file agentic_astra-0.0.5-py3-none-any.whl.
File metadata
- Download URL: agentic_astra-0.0.5-py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10aa765b614bc61e84ec62e8b7010797bc69356297202dd77b43d69ff7d6769d
|
|
| MD5 |
d7c7dfa9423d1e3fd44e655efe800968
|
|
| BLAKE2b-256 |
af5b2a8714acb680210eda44b31fa028628b891790f3492662cd4fcbb5e1e289
|