Skip to content

Commit 07b8818

Browse files
committed
Enhanced MCP to work with both direct parameters and Smithery config
1 parent 0736b7e commit 07b8818

File tree

3 files changed

+55
-22
lines changed

3 files changed

+55
-22
lines changed

index.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ const { spawn } = require('child_process');
88
const args = process.argv.slice(2);
99
let tokenIndex = args.indexOf('--token');
1010
let baseIndex = args.indexOf('--base');
11+
let configIndex = args.indexOf('--config');
1112

12-
// Extract token and base ID
13+
// Extract token, base ID and config
1314
const token = tokenIndex !== -1 && tokenIndex + 1 < args.length ? args[tokenIndex + 1] : null;
1415
const baseId = baseIndex !== -1 && baseIndex + 1 < args.length ? args[baseIndex + 1] : null;
16+
const config = configIndex !== -1 && configIndex + 1 < args.length ? args[configIndex + 1] : null;
1517

1618
console.log('🔌 Airtable MCP - Connecting your AI to Airtable');
1719
console.log('-----------------------------------------------');
@@ -76,18 +78,33 @@ if (token) {
7678
if (baseId) {
7779
scriptArgs.push('--base', baseId);
7880
}
79-
80-
console.log(`🚀 Starting Airtable MCP Server using ${pythonPath}`);
81-
if (token) {
82-
console.log('✅ Using provided API token');
81+
if (config) {
82+
scriptArgs.push('--config', config);
83+
84+
// Try to extract and log info from config
85+
try {
86+
const configObj = JSON.parse(config);
87+
if (configObj.airtable_token) {
88+
console.log('✅ Using API token from config');
89+
}
90+
if (configObj.base_id) {
91+
console.log(`✅ Using base ID from config: ${configObj.base_id}`);
92+
}
93+
} catch (e) {
94+
console.warn('⚠️ Could not parse config JSON, passing it directly to Python script');
95+
}
8396
} else {
84-
console.log('⚠️ No API token provided, will try to use .env file');
85-
}
97+
if (token) {
98+
console.log('✅ Using provided API token');
99+
} else {
100+
console.log('⚠️ No API token provided, will try to use .env file');
101+
}
86102

87-
if (baseId) {
88-
console.log(`✅ Using base ID: ${baseId}`);
89-
} else {
90-
console.log('ℹ️ No base ID provided, will need to set one later');
103+
if (baseId) {
104+
console.log(`✅ Using base ID: ${baseId}`);
105+
} else {
106+
console.log('ℹ️ No base ID provided, will need to set one later');
107+
}
91108
}
92109

93110
// Execute the Python script

inspector_server.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def parse_args():
2323
parser = argparse.ArgumentParser(description="Airtable MCP Server")
2424
parser.add_argument("--token", dest="api_token", help="Airtable Personal Access Token")
2525
parser.add_argument("--base", dest="base_id", help="Airtable Base ID")
26+
parser.add_argument("--config", dest="config_json", help="Configuration as JSON (for Smithery integration)")
2627
return parser.parse_args()
2728

2829
# Set up logging
@@ -32,28 +33,45 @@ def parse_args():
3233
# Parse arguments
3334
args = parse_args()
3435

36+
# Handle config JSON from Smithery if provided
37+
config = {}
38+
if args.config_json:
39+
try:
40+
# Strip any trailing quotes or backslashes that might be present
41+
config_str = args.config_json.rstrip('\\"')
42+
logger.info(f"Parsing config: {config_str}")
43+
config = json.loads(config_str)
44+
logger.info(f"Successfully parsed config: {config}")
45+
except json.JSONDecodeError as e:
46+
logger.error(f"Failed to parse config JSON: {e}")
47+
logger.error(f"Raw config string: {args.config_json}")
48+
3549
# Create MCP server
3650
app = FastMCP("Airtable Tools")
3751

38-
# Get token from arguments or environment
39-
token = args.api_token or os.environ.get("AIRTABLE_PERSONAL_ACCESS_TOKEN", "")
40-
base_id = args.base_id or os.environ.get("AIRTABLE_BASE_ID", "")
52+
# Get token from arguments, config, or environment
53+
token = args.api_token or config.get("airtable_token", "") or os.environ.get("AIRTABLE_PERSONAL_ACCESS_TOKEN", "")
54+
# Clean up token if it has trailing quote
55+
if token and token.endswith('"'):
56+
token = token[:-1]
57+
58+
base_id = args.base_id or config.get("base_id", "") or os.environ.get("AIRTABLE_BASE_ID", "")
4159

4260
if not token:
43-
logger.warning("No Airtable API token provided. Use --token or set AIRTABLE_PERSONAL_ACCESS_TOKEN environment variable.")
61+
logger.warning("No Airtable API token provided. Use --token, --config, or set AIRTABLE_PERSONAL_ACCESS_TOKEN environment variable.")
4462
else:
4563
logger.info(f"Using Airtable token: {token[:5]}...{token[-5:]}")
4664

4765
if base_id:
4866
logger.info(f"Using base ID: {base_id}")
4967
else:
50-
logger.warning("No base ID provided. Use --base or set AIRTABLE_BASE_ID environment variable.")
68+
logger.warning("No base ID provided. Use --base, --config, or set AIRTABLE_BASE_ID environment variable.")
5169

5270
# Helper functions for Airtable API calls
5371
async def api_call(endpoint, method="GET", data=None, params=None):
5472
"""Make an Airtable API call"""
5573
if not token:
56-
return {"error": "No Airtable API token provided. Use --token or set AIRTABLE_PERSONAL_ACCESS_TOKEN environment variable."}
74+
return {"error": "No Airtable API token provided. Use --token, --config, or set AIRTABLE_PERSONAL_ACCESS_TOKEN environment variable."}
5775

5876
headers = {
5977
"Authorization": f"Bearer {token}",

smithery.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ startCommand:
1717
required: ["airtable_token"]
1818
commandFunction: |
1919
(config) => {
20-
// Use Python directly with the new inspector_server.py
20+
// Pass config as a JSON string to the inspector_server.py
21+
const configStr = JSON.stringify(config);
2122
return {
2223
command: "python3.10",
23-
args: ["inspector_server.py",
24-
"--token", config.airtable_token,
25-
...(config.base_id ? ["--base", config.base_id] : [])
26-
],
24+
args: ["inspector_server.py", "--config", configStr],
2725
env: {}
2826
};
2927
}

0 commit comments

Comments
 (0)