Skip to main content
Glama

Quick-start Auto MCP

auto_mcp_json.py2 kB
import os import json import sys from pathlib import Path from dotenv import load_dotenv def get_env_variables(): """ Load environment variables and return required variables as a dictionary. Returns: dict: Dictionary containing environment variables and default configuration values """ load_dotenv() required_vars = [ "OPENAI_API_KEY", ] config_vars = {"DEFAULT_TOP_K": "5"} env_dict = {} for var in required_vars: value = os.getenv(var) if value: env_dict[var] = value env_dict.update(config_vars) return env_dict def create_mcp_json(): """ Create a Model Context Protocol (MCP) server configuration JSON file. This function generates a configuration file that defines how the MCP server should be launched, including the Python interpreter path, server script location, and necessary environment variables. Returns: str: Path to the created JSON configuration file """ project_root = Path(__file__).parent.absolute() # .venv python executable path if os.name == 'nt': # Windows python_path = str(project_root.parent / ".venv" / "Scripts" / "python.exe") else: # Mac, Ubuntu etc python_path = str(project_root.parent / ".venv" / "bin" / "python") server_script = project_root / "mcp_server.py" env_vars = get_env_variables() config = { "mcpServers": { "rag-mcp": { "command": python_path, "args": [str(server_script)], "env": env_vars, } } } json_path = project_root / "mcp_config.json" with open(json_path, "w", encoding="utf-8") as f: json.dump(config, f, indent=2) print(f"MCP configuration file has been created: {json_path}") print(f"Generated environment variables: {', '.join(env_vars.keys())}") return str(json_path) if __name__ == "__main__": create_mcp_json()

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/teddynote-lab/mcp-usecase'

If you have feedback or need assistance with the MCP directory API, please join our Discord server