This repository was archived by the owner on Mar 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexamples.js
More file actions
executable file
·79 lines (65 loc) · 2.3 KB
/
Copy pathexamples.js
File metadata and controls
executable file
·79 lines (65 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
// Example usage script for TwitterAPI MCP Server
// This script demonstrates the available tools and usage
const { execSync } = require('child_process');
function runMCPCommand(request) {
try {
const result = execSync(`echo '${JSON.stringify(request)}' | node build/index.js`, {
encoding: 'utf8',
timeout: 10000
});
// Parse the JSON response from stdout
const lines = result.split('\n').filter(line => line.trim());
const jsonLine = lines.find(line => line.startsWith('{'));
if (jsonLine) {
return JSON.parse(jsonLine);
}
throw new Error('No JSON response found');
} catch (error) {
throw new Error(`MCP command failed: ${error.message}`);
}
}
async function main() {
console.log('🐦 TwitterAPI MCP Server Example Usage\n');
try {
// List available tools
console.log('📋 Listing available tools...');
const toolsResponse = runMCPCommand({
jsonrpc: '2.0',
id: 1,
method: 'tools/list',
params: {}
});
if (toolsResponse.result && toolsResponse.result.tools) {
const tools = toolsResponse.result.tools;
console.log(`Found ${tools.length} tools:\n`);
tools.forEach((tool, index) => {
console.log(`${index + 1}. ${tool.name}`);
console.log(` Description: ${tool.description}`);
console.log(` Required params: ${tool.inputSchema.required?.join(', ') || 'none'}\n`);
});
}
console.log('💡 Example usage with API key:');
console.log('TWITTERAPI_API_KEY="your_key" node examples.js\n');
console.log('🔧 To test a specific tool call:');
console.log('echo \'{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "get_user_by_username", "arguments": {"username": "elonmusk"}}}\' | TWITTERAPI_API_KEY="your_key" node build/index.js\n');
console.log('🏠 Claude Desktop Configuration:');
console.log(JSON.stringify({
"mcpServers": {
"twitterapi": {
"command": "npx",
"args": ["twitterapi-mcp"],
"env": {
"TWITTERAPI_API_KEY": "your_api_key_here"
}
}
}
}, null, 2));
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
}
if (require.main === module) {
main().catch(console.error);
}