Skip to main content
Glama

PostgreSQL MCP Server

by gharshit
resources.py1.61 kB
##? Import Libraries from . import mcp ## DEFn_: FIRST RESOURCE: to get context of the database. This can have deep detailed tables and columns information. @mcp.resource(uri="db://context", description="Resource to get context of the database", mime_type="text/plain") def database_context() -> str: """ Objective: Resource to get context of the database """ text_ = """ user.id = primary key of the user table orders.user_id = foreign key for referencing user.id orders.total = total amount of the order in INR. status values: pending, shipped, delivered, cancelled """ return text_ ## DEFn_: SECOND RESOURCE: to get context of the schema. Providing schema related infromation information. @mcp.resource(uri="db://schema/{schema_name}", description="Resource to get context of the schema", mime_type="application/json") def schema_context(schema_name: str) -> dict[str, str]: """ Objective: Resource to get context of the schema """ ## only to simulate respource template. if schema_name == "public": result = {"result": ["SELECT COUNT(*) FROM users", "SELECT COUNT(*) FROM orders"]} else: result = {"result": ["SELECT COUNT(*) FROM users WHERE schema_name = '{schema_name}'", "SELECT user_id,SUM(total) AS total_amount FROM orders WHERE schema_name = '{schema_name}' GROUP BY user_id", "SELECT * FROM orders WHERE schema_name = '{schema_name}' ORDER BY created_at DESC LIMIT 5"]} return result

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/gharshit/mcpServer'

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