Initial commit
This commit is contained in:
51
skills/subgraph-explorer/scripts/check_mcp_status.sh
Executable file
51
skills/subgraph-explorer/scripts/check_mcp_status.sh
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Check the status of the Subgraph MCP Server
|
||||
#
|
||||
# This script checks if the subgraph-mcp Docker container is running
|
||||
# and verifies that the endpoints are accessible.
|
||||
|
||||
set -e
|
||||
|
||||
echo "🔍 Checking Subgraph MCP Server status..."
|
||||
echo ""
|
||||
|
||||
# Check if container is running
|
||||
if docker ps | grep -q "subgraph-mcp-server"; then
|
||||
echo "✅ Container: Running"
|
||||
|
||||
# Get container uptime
|
||||
UPTIME=$(docker ps --filter "name=subgraph-mcp-server" --format "{{.Status}}")
|
||||
echo " Status: $UPTIME"
|
||||
|
||||
# Check SSE endpoint
|
||||
echo ""
|
||||
echo "🌐 Checking endpoints..."
|
||||
if curl -s -f http://localhost:8000 > /dev/null 2>&1; then
|
||||
echo " ✅ SSE endpoint (port 8000): Accessible"
|
||||
else
|
||||
echo " ⚠️ SSE endpoint (port 8000): Not responding"
|
||||
fi
|
||||
|
||||
# Check metrics endpoint
|
||||
if curl -s -f http://localhost:9091/metrics > /dev/null 2>&1; then
|
||||
echo " ✅ Metrics endpoint (port 9091): Accessible"
|
||||
else
|
||||
echo " ⚠️ Metrics endpoint (port 9091): Not responding"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "📊 Recent logs:"
|
||||
docker logs --tail 10 subgraph-mcp-server
|
||||
|
||||
elif docker ps -a | grep -q "subgraph-mcp-server"; then
|
||||
echo "❌ Container: Stopped"
|
||||
echo ""
|
||||
echo " Start with: scripts/start_mcp_server.sh"
|
||||
echo " Or: docker-compose up -d (from subgraph-mcp directory)"
|
||||
else
|
||||
echo "❌ Container: Not found"
|
||||
echo ""
|
||||
echo " The subgraph-mcp-server container doesn't exist."
|
||||
echo " Start it with: scripts/start_mcp_server.sh"
|
||||
fi
|
||||
160
skills/subgraph-explorer/scripts/export_query.py
Executable file
160
skills/subgraph-explorer/scripts/export_query.py
Executable file
@@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Export GraphQL Query Utility
|
||||
|
||||
This script helps export discovered GraphQL queries into reusable formats
|
||||
for easy integration into projects. It supports multiple output formats:
|
||||
- JavaScript/TypeScript module
|
||||
- Python module
|
||||
- Plain GraphQL file
|
||||
- JSON format with metadata
|
||||
|
||||
Usage:
|
||||
python3 export_query.py <output_file> [--format js|py|graphql|json] [--name QueryName]
|
||||
|
||||
Then paste your GraphQL query when prompted, and press Ctrl+D (Unix) or Ctrl+Z (Windows) when done.
|
||||
|
||||
Examples:
|
||||
# Export as JavaScript
|
||||
python3 export_query.py queries/myQuery.js --format js --name GetLatestSwaps
|
||||
|
||||
# Export as Python
|
||||
python3 export_query.py queries/myQuery.py --format py --name get_latest_swaps
|
||||
|
||||
# Export as plain GraphQL
|
||||
python3 export_query.py queries/myQuery.graphql --format graphql
|
||||
"""
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def format_js(query: str, name: str, description: str = "") -> str:
|
||||
"""Format query as JavaScript/TypeScript module."""
|
||||
comment = f"/**\n * {description}\n */\n" if description else ""
|
||||
return f"""{comment}export const {name} = `
|
||||
{query}
|
||||
`;
|
||||
"""
|
||||
|
||||
|
||||
def format_python(query: str, name: str, description: str = "") -> str:
|
||||
"""Format query as Python module."""
|
||||
docstring = f' """{description}"""\n' if description else ""
|
||||
return f'''{name} = """
|
||||
{query}
|
||||
"""
|
||||
{docstring}
|
||||
'''
|
||||
|
||||
|
||||
def format_graphql(query: str, description: str = "") -> str:
|
||||
"""Format as plain GraphQL with optional comment."""
|
||||
comment = f"# {description}\n\n" if description else ""
|
||||
return f"{comment}{query}\n"
|
||||
|
||||
|
||||
def format_json(query: str, name: str, description: str = "", variables: dict = None) -> str:
|
||||
"""Format as JSON with metadata."""
|
||||
data = {
|
||||
"name": name,
|
||||
"description": description,
|
||||
"query": query,
|
||||
"variables": variables or {},
|
||||
"exported_at": datetime.now().isoformat()
|
||||
}
|
||||
return json.dumps(data, indent=2)
|
||||
|
||||
|
||||
def read_multiline_input(prompt: str) -> str:
|
||||
"""Read multiline input from stdin."""
|
||||
print(prompt)
|
||||
print("(Press Ctrl+D on Unix/Mac or Ctrl+Z on Windows when done)")
|
||||
print("-" * 60)
|
||||
lines = []
|
||||
try:
|
||||
while True:
|
||||
line = input()
|
||||
lines.append(line)
|
||||
except EOFError:
|
||||
pass
|
||||
print("-" * 60)
|
||||
return "\n".join(lines).strip()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Export GraphQL queries into various formats for project use",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog=__doc__
|
||||
)
|
||||
parser.add_argument("output", help="Output file path")
|
||||
parser.add_argument(
|
||||
"--format",
|
||||
choices=["js", "py", "graphql", "json"],
|
||||
help="Output format (default: inferred from file extension)"
|
||||
)
|
||||
parser.add_argument("--name", help="Query name (required for js/py/json formats)")
|
||||
parser.add_argument("--description", default="", help="Query description")
|
||||
parser.add_argument("--variables", help="JSON string of query variables (for json format)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Infer format from extension if not provided
|
||||
output_path = Path(args.output)
|
||||
format_type = args.format
|
||||
if not format_type:
|
||||
ext = output_path.suffix.lower()
|
||||
format_map = {".js": "js", ".ts": "js", ".py": "py", ".graphql": "graphql", ".gql": "graphql", ".json": "json"}
|
||||
format_type = format_map.get(ext)
|
||||
if not format_type:
|
||||
print(f"❌ Error: Cannot infer format from extension '{ext}'. Please specify --format", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Validate name requirement
|
||||
if format_type in ["js", "py", "json"] and not args.name:
|
||||
print(f"❌ Error: --name is required for {format_type} format", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Read the GraphQL query
|
||||
query = read_multiline_input("\n📝 Paste your GraphQL query:")
|
||||
if not query:
|
||||
print("❌ Error: No query provided", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Parse variables if provided
|
||||
variables = None
|
||||
if args.variables:
|
||||
try:
|
||||
variables = json.loads(args.variables)
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"❌ Error: Invalid JSON in --variables: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Format the output
|
||||
formatters = {
|
||||
"js": lambda: format_js(query, args.name, args.description),
|
||||
"py": lambda: format_python(query, args.name, args.description),
|
||||
"graphql": lambda: format_graphql(query, args.description),
|
||||
"json": lambda: format_json(query, args.name, args.description, variables)
|
||||
}
|
||||
|
||||
output = formatters[format_type]()
|
||||
|
||||
# Create parent directory if it doesn't exist
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Write the output
|
||||
output_path.write_text(output)
|
||||
|
||||
print(f"\n✅ Query exported successfully to: {output_path}")
|
||||
print(f" Format: {format_type}")
|
||||
if args.name:
|
||||
print(f" Name: {args.name}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
62
skills/subgraph-explorer/scripts/start_mcp_server.sh
Executable file
62
skills/subgraph-explorer/scripts/start_mcp_server.sh
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Start the Subgraph MCP Server using Docker Compose
|
||||
#
|
||||
# This script starts the subgraph-mcp server in Docker, which exposes:
|
||||
# - Port 8000: SSE endpoint for MCP communication
|
||||
# - Port 9091: Prometheus metrics endpoint
|
||||
#
|
||||
# The server runs in SSE mode and uses the subgraphs.json configuration
|
||||
# from the subgraph-mcp project directory.
|
||||
|
||||
set -e
|
||||
|
||||
# Default path to subgraph-mcp project
|
||||
SUBGRAPH_MCP_PATH="${SUBGRAPH_MCP_PATH:-$HOME/Workspace/subgraph-mcp}"
|
||||
|
||||
echo "🚀 Starting Subgraph MCP Server..."
|
||||
echo " Project path: $SUBGRAPH_MCP_PATH"
|
||||
|
||||
# Check if the directory exists
|
||||
if [ ! -d "$SUBGRAPH_MCP_PATH" ]; then
|
||||
echo "❌ Error: Directory not found: $SUBGRAPH_MCP_PATH"
|
||||
echo " Set SUBGRAPH_MCP_PATH environment variable to the correct path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if docker-compose.yml exists
|
||||
if [ ! -f "$SUBGRAPH_MCP_PATH/docker-compose.yml" ]; then
|
||||
echo "❌ Error: docker-compose.yml not found in $SUBGRAPH_MCP_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if subgraphs.json exists
|
||||
if [ ! -f "$SUBGRAPH_MCP_PATH/subgraphs.json" ]; then
|
||||
echo "⚠️ Warning: subgraphs.json not found in $SUBGRAPH_MCP_PATH"
|
||||
echo " The server may not work properly without configuration"
|
||||
fi
|
||||
|
||||
# Change to the project directory
|
||||
cd "$SUBGRAPH_MCP_PATH"
|
||||
|
||||
# Start the server using docker-compose
|
||||
echo " Starting Docker container..."
|
||||
docker-compose up -d
|
||||
|
||||
# Wait for the server to be ready
|
||||
echo " Waiting for server to be ready..."
|
||||
sleep 3
|
||||
|
||||
# Check if the container is running
|
||||
if docker ps | grep -q "subgraph-mcp-server"; then
|
||||
echo "✅ Subgraph MCP Server started successfully"
|
||||
echo " SSE endpoint: http://localhost:8000"
|
||||
echo " Metrics endpoint: http://localhost:9091/metrics"
|
||||
echo ""
|
||||
echo " View logs: docker logs -f subgraph-mcp-server"
|
||||
echo " Stop server: docker-compose down (from $SUBGRAPH_MCP_PATH)"
|
||||
else
|
||||
echo "❌ Failed to start server. Check logs with:"
|
||||
echo " docker logs subgraph-mcp-server"
|
||||
exit 1
|
||||
fi
|
||||
28
skills/subgraph-explorer/scripts/stop_mcp_server.sh
Executable file
28
skills/subgraph-explorer/scripts/stop_mcp_server.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Stop the Subgraph MCP Server
|
||||
#
|
||||
# This script stops the subgraph-mcp Docker container and cleans up resources.
|
||||
|
||||
set -e
|
||||
|
||||
# Default path to subgraph-mcp project
|
||||
SUBGRAPH_MCP_PATH="${SUBGRAPH_MCP_PATH:-$HOME/Workspace/subgraph-mcp}"
|
||||
|
||||
echo "🛑 Stopping Subgraph MCP Server..."
|
||||
echo " Project path: $SUBGRAPH_MCP_PATH"
|
||||
|
||||
# Check if the directory exists
|
||||
if [ ! -d "$SUBGRAPH_MCP_PATH" ]; then
|
||||
echo "❌ Error: Directory not found: $SUBGRAPH_MCP_PATH"
|
||||
echo " Set SUBGRAPH_MCP_PATH environment variable to the correct path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Change to the project directory
|
||||
cd "$SUBGRAPH_MCP_PATH"
|
||||
|
||||
# Stop the server
|
||||
docker-compose down
|
||||
|
||||
echo "✅ Subgraph MCP Server stopped"
|
||||
Reference in New Issue
Block a user