twitterviewer-mcp 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +223 -2
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +34 -0
- package/dist/proxy.d.ts +19 -0
- package/dist/proxy.js +139 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/package.json +48 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TwitterViewer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,224 @@
|
|
|
1
|
-
#
|
|
1
|
+
# twitterviewer-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MCP server that lets AI agents read public X (Twitter) posts, threads, profiles and replies as Markdown. Three read-only tools, hosted by [TwitterViewer](https://twitterviewer.ai) at `https://twitterviewer.ai/mcp`. Independent service, not affiliated with X.
|
|
4
|
+
|
|
5
|
+
Using the tools needs a [Plus](https://twitterviewer.ai/pricing) subscription, on either connection. There are two ways to connect:
|
|
6
|
+
|
|
7
|
+
| | Use it when | Sign-in |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| **[Remote server](#remote-server-recommended)** (recommended) | Your client supports remote (Streamable HTTP) MCP servers | Browser sign-in (OAuth), or an API key |
|
|
10
|
+
| **[Local stdio](#local-stdio-server)** (`npx -y twitterviewer-mcp`) | Your client only starts local servers | API key |
|
|
11
|
+
|
|
12
|
+
## Remote server (recommended)
|
|
13
|
+
|
|
14
|
+
Nothing to install or update. The first time you connect, your client opens the browser to sign in to your TwitterViewer account (Plus). No API key needed.
|
|
15
|
+
|
|
16
|
+
### Claude Code
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
claude mcp add --transport http twitterviewer https://twitterviewer.ai/mcp
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then run `/mcp` inside Claude Code to sign in.
|
|
23
|
+
|
|
24
|
+
### Claude Desktop and claude.ai
|
|
25
|
+
|
|
26
|
+
Open **Settings → Connectors → Add custom connector** and enter `https://twitterviewer.ai/mcp`.
|
|
27
|
+
|
|
28
|
+
### Cursor
|
|
29
|
+
|
|
30
|
+
`~/.cursor/mcp.json`:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"mcpServers": {
|
|
35
|
+
"twitterviewer": { "url": "https://twitterviewer.ai/mcp" }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Codex
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
codex mcp add twitterviewer --url https://twitterviewer.ai/mcp
|
|
44
|
+
codex mcp login twitterviewer
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or add it to `~/.codex/config.toml` and run the login command:
|
|
48
|
+
|
|
49
|
+
```toml
|
|
50
|
+
[mcp_servers.twitterviewer]
|
|
51
|
+
url = "https://twitterviewer.ai/mcp"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### VS Code (GitHub Copilot)
|
|
55
|
+
|
|
56
|
+
`~/.copilot/mcp-config.json`, or `.mcp.json` in the workspace root:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"mcpServers": {
|
|
61
|
+
"twitterviewer": {
|
|
62
|
+
"type": "http",
|
|
63
|
+
"url": "https://twitterviewer.ai/mcp",
|
|
64
|
+
"tools": ["*"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Windsurf (Devin Desktop)
|
|
71
|
+
|
|
72
|
+
`~/.config/devin/mcp_config.json`:
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"mcpServers": {
|
|
77
|
+
"twitterviewer": {
|
|
78
|
+
"url": "https://twitterviewer.ai/mcp",
|
|
79
|
+
"transport": "http"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### With an API key instead
|
|
86
|
+
|
|
87
|
+
For servers, CI and clients that cannot open a browser, create a key at <https://twitterviewer.ai/account/api> and send it as `Authorization: Bearer <key>`.
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
claude mcp add --transport http twitterviewer https://twitterviewer.ai/mcp \
|
|
91
|
+
--header "Authorization: Bearer $TWITTERVIEWER_API_KEY"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Cursor:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"mcpServers": {
|
|
99
|
+
"twitterviewer": {
|
|
100
|
+
"url": "https://twitterviewer.ai/mcp",
|
|
101
|
+
"headers": { "Authorization": "Bearer ${env:TWITTERVIEWER_API_KEY}" }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Codex:
|
|
108
|
+
|
|
109
|
+
```toml
|
|
110
|
+
[mcp_servers.twitterviewer]
|
|
111
|
+
url = "https://twitterviewer.ai/mcp"
|
|
112
|
+
bearer_token_env_var = "TWITTERVIEWER_API_KEY"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Local stdio server
|
|
116
|
+
|
|
117
|
+
The `twitterviewer-mcp` package runs on your machine and forwards every request to the remote server, so the tools are always the same as the hosted ones. It needs Node.js 20 or newer. Tool calls need an API key from <https://twitterviewer.ai/account/api> (Plus).
|
|
118
|
+
|
|
119
|
+
### Claude Desktop, Cursor and other JSON configs
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"mcpServers": {
|
|
124
|
+
"twitterviewer": {
|
|
125
|
+
"command": "npx",
|
|
126
|
+
"args": ["-y", "twitterviewer-mcp"],
|
|
127
|
+
"env": { "TWITTERVIEWER_API_KEY": "tv_live_..." }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Claude Code
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
claude mcp add --env TWITTERVIEWER_API_KEY=tv_live_... --transport stdio twitterviewer -- npx -y twitterviewer-mcp
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Codex
|
|
140
|
+
|
|
141
|
+
```toml
|
|
142
|
+
[mcp_servers.twitterviewer]
|
|
143
|
+
command = "npx"
|
|
144
|
+
args = ["-y", "twitterviewer-mcp"]
|
|
145
|
+
env = { TWITTERVIEWER_API_KEY = "tv_live_..." }
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Docker
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
docker build -t twitterviewer-mcp .
|
|
152
|
+
docker run -i --rm -e TWITTERVIEWER_API_KEY twitterviewer-mcp
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Environment variables
|
|
156
|
+
|
|
157
|
+
| Variable | Required | Description |
|
|
158
|
+
| --- | --- | --- |
|
|
159
|
+
| `TWITTERVIEWER_API_KEY` | for tool calls | API key. Without it the server still starts and lists the tools; a tool call explains how to create one. With a key whose account has no Plus plan, requests fail with a message saying Plus is required. |
|
|
160
|
+
| `TWITTERVIEWER_BASE_URL` | no | Site that hosts `/mcp`. Default `https://twitterviewer.ai`. |
|
|
161
|
+
|
|
162
|
+
## Tools
|
|
163
|
+
|
|
164
|
+
All tools are read-only: they never post, like or follow, and they never ask for your X account.
|
|
165
|
+
|
|
166
|
+
### `convert_x_url`
|
|
167
|
+
|
|
168
|
+
Turn an X (Twitter) post, thread, or profile link into clean Markdown (or text / JSON). Costs 1 credit per post returned (quoted posts count too); author profile data is free; errors are free. A repeated call for the same link and options within 10 minutes is free. Profile links return recent posts (default 20, up to 200).
|
|
169
|
+
|
|
170
|
+
| Argument | Required | Description |
|
|
171
|
+
| --- | --- | --- |
|
|
172
|
+
| `url` | yes | X post, thread or profile URL, or an @handle |
|
|
173
|
+
| `scope` | no | `thread` (default): the author's whole thread; `post`: only this post; `conversation`: thread plus the first page of replies |
|
|
174
|
+
| `format` | no | `markdown` (default), `obsidian` (with YAML frontmatter), `text`, or `json` |
|
|
175
|
+
| `stats` | no | Engagement numbers: `all` (default), `root` (first post only), `off` |
|
|
176
|
+
| `max` | no | Profile links only: how many recent posts (default 20) |
|
|
177
|
+
|
|
178
|
+
### `get_x_replies`
|
|
179
|
+
|
|
180
|
+
Replies to one X post. Costs 1 credit per reply returned; repeating the same call within 10 minutes returns the same result for free.
|
|
181
|
+
|
|
182
|
+
| Argument | Required | Description |
|
|
183
|
+
| --- | --- | --- |
|
|
184
|
+
| `url` | yes | X post URL |
|
|
185
|
+
| `max` | no | How many replies (default 20, up to 100) |
|
|
186
|
+
|
|
187
|
+
### `get_credits`
|
|
188
|
+
|
|
189
|
+
Remaining TwitterViewer credits: plan credits for the current cycle plus any that never expire. Calling it costs no credits. No arguments.
|
|
190
|
+
|
|
191
|
+
## Try it
|
|
192
|
+
|
|
193
|
+
- "Read https://x.com/jack/status/20 as Markdown."
|
|
194
|
+
- "Summarize the recent posts from @NASA."
|
|
195
|
+
- "What are people replying to this post?" followed by the link.
|
|
196
|
+
|
|
197
|
+
## Credits
|
|
198
|
+
|
|
199
|
+
- **1 credit = 1 post returned.** A quoted post counts as one more post.
|
|
200
|
+
- [Plus](https://twitterviewer.ai/pricing) includes the MCP server, the API and the CLI, with 3,000 credits a month.
|
|
201
|
+
- Errors and empty results are free.
|
|
202
|
+
- Repeating a conversion or replies call with the same parameters on the same account within 10 minutes returns the first result and is not charged again. If your balance cut that result short and you have credits again, the repeat counts as a new call.
|
|
203
|
+
- Requests are limited per account: 30 a minute.
|
|
204
|
+
|
|
205
|
+
## Links
|
|
206
|
+
|
|
207
|
+
- [TwitterViewer MCP Server](https://twitterviewer.ai/twitterviewer-mcp-server): setup and overview
|
|
208
|
+
- [API docs](https://twitterviewer.ai/docs/api): authentication, tool arguments and the REST API
|
|
209
|
+
- [`twitterviewer`](https://www.npmjs.com/package/twitterviewer): TypeScript SDK and command line client
|
|
210
|
+
|
|
211
|
+
## Development
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
bun install
|
|
215
|
+
bun run typecheck
|
|
216
|
+
bun run test
|
|
217
|
+
bun run build
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Tool definitions live only on the remote server; this package does not declare any. Integration tests are skipped unless both `TWITTERVIEWER_BASE_URL` (for example `http://localhost:3400`) and `TWITTERVIEWER_API_KEY` are set; they need a Plus account's key and use only calls that cost no credits.
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
[MIT](LICENSE)
|
package/dist/bin.d.ts
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { API_KEY_URL, DEFAULT_BASE_URL, createProxyServer } from './proxy.js';
|
|
4
|
+
import { VERSION } from './version.js';
|
|
5
|
+
const HELP = `twitterviewer-mcp ${VERSION}
|
|
6
|
+
|
|
7
|
+
Local stdio MCP server that forwards to the hosted TwitterViewer MCP server.
|
|
8
|
+
It is meant to be started by an MCP client, for example with: npx -y twitterviewer-mcp
|
|
9
|
+
|
|
10
|
+
Environment:
|
|
11
|
+
TWITTERVIEWER_API_KEY API key (needs Plus), from ${API_KEY_URL}
|
|
12
|
+
TWITTERVIEWER_BASE_URL Site that hosts /mcp (default ${DEFAULT_BASE_URL})
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
-h, --help Show this help
|
|
16
|
+
-v, --version Show the version
|
|
17
|
+
`;
|
|
18
|
+
async function main(args) {
|
|
19
|
+
if (args.includes('-h') || args.includes('--help'))
|
|
20
|
+
return void process.stdout.write(HELP);
|
|
21
|
+
if (args.includes('-v') || args.includes('--version'))
|
|
22
|
+
return void process.stdout.write(`${VERSION}\n`);
|
|
23
|
+
// stdout carries the protocol; anything for humans goes to stderr.
|
|
24
|
+
const apiKey = process.env.TWITTERVIEWER_API_KEY;
|
|
25
|
+
if (!apiKey?.trim())
|
|
26
|
+
console.error(`twitterviewer-mcp: TWITTERVIEWER_API_KEY is not set. Create a key (needs Plus) at ${API_KEY_URL}`);
|
|
27
|
+
const server = await createProxyServer({ apiKey, baseUrl: process.env.TWITTERVIEWER_BASE_URL });
|
|
28
|
+
server.onerror = (error) => console.error(`twitterviewer-mcp: ${error.message}`);
|
|
29
|
+
await server.connect(new StdioServerTransport());
|
|
30
|
+
}
|
|
31
|
+
main(process.argv.slice(2)).catch((error) => {
|
|
32
|
+
console.error(`twitterviewer-mcp: ${error instanceof Error ? error.message : String(error)}`);
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
});
|
package/dist/proxy.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
export declare const DEFAULT_BASE_URL = "https://twitterviewer.ai";
|
|
3
|
+
export declare const API_KEY_URL = "https://twitterviewer.ai/account/api";
|
|
4
|
+
export declare const PRICING_URL = "https://twitterviewer.ai/pricing";
|
|
5
|
+
export interface ProxyOptions {
|
|
6
|
+
/** Sent as `Authorization: Bearer <key>`. */
|
|
7
|
+
apiKey?: string | undefined;
|
|
8
|
+
/** Site that hosts `/mcp`. Defaults to {@link DEFAULT_BASE_URL}. */
|
|
9
|
+
baseUrl?: string | undefined;
|
|
10
|
+
/** Replaces the global `fetch`. */
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
connectTimeoutMs?: number;
|
|
13
|
+
requestTimeoutMs?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Builds a local MCP server that forwards every request to the remote Streamable HTTP server.
|
|
17
|
+
* Nothing about tools is defined here: names, descriptions, schemas and results all come from the remote.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createProxyServer(options?: ProxyOptions): Promise<Server>;
|
package/dist/proxy.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
+
import { StreamableHTTPClientTransport, StreamableHTTPError } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
3
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
+
import { ErrorCode, McpError, ResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { VERSION } from './version.js';
|
|
6
|
+
export const DEFAULT_BASE_URL = 'https://twitterviewer.ai';
|
|
7
|
+
export const API_KEY_URL = 'https://twitterviewer.ai/account/api';
|
|
8
|
+
export const PRICING_URL = 'https://twitterviewer.ai/pricing';
|
|
9
|
+
const CONNECT_TIMEOUT_MS = 10_000;
|
|
10
|
+
/** Long profile conversions can take well over the SDK default of 60 seconds. */
|
|
11
|
+
const REQUEST_TIMEOUT_MS = 180_000;
|
|
12
|
+
/**
|
|
13
|
+
* Builds a local MCP server that forwards every request to the remote Streamable HTTP server.
|
|
14
|
+
* Nothing about tools is defined here: names, descriptions, schemas and results all come from the remote.
|
|
15
|
+
*/
|
|
16
|
+
export async function createProxyServer(options = {}) {
|
|
17
|
+
const apiKey = options.apiKey?.trim() || undefined;
|
|
18
|
+
const url = new URL(`${(options.baseUrl?.trim() || DEFAULT_BASE_URL).replace(/\/+$/, '')}/mcp`);
|
|
19
|
+
const baseFetch = options.fetch ?? fetch;
|
|
20
|
+
const connectTimeout = options.connectTimeoutMs ?? CONNECT_TIMEOUT_MS;
|
|
21
|
+
const requestTimeout = options.requestTimeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
22
|
+
const open = async () => {
|
|
23
|
+
const client = new Client({ name: 'twitterviewer-mcp', version: VERSION });
|
|
24
|
+
const transport = new StreamableHTTPClientTransport(url, {
|
|
25
|
+
requestInit: {
|
|
26
|
+
headers: {
|
|
27
|
+
'user-agent': `twitterviewer-mcp/${VERSION}`,
|
|
28
|
+
...(apiKey && { authorization: `Bearer ${apiKey}` }),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
// The remote is stateless and has no server-initiated stream. Answering the optional GET locally
|
|
32
|
+
// keeps it from counting against the account's per-minute request limit.
|
|
33
|
+
fetch: async (input, init) => (init?.method === 'GET' ? new Response(null, { status: 405 }) : baseFetch(input, init)),
|
|
34
|
+
});
|
|
35
|
+
await client.connect(transport, { timeout: connectTimeout });
|
|
36
|
+
return client;
|
|
37
|
+
};
|
|
38
|
+
let upstream;
|
|
39
|
+
const connect = () => (upstream ??= open().catch((error) => {
|
|
40
|
+
upstream = undefined;
|
|
41
|
+
throw error;
|
|
42
|
+
}));
|
|
43
|
+
const explain = (error) => describeFailure(error, { hasKey: apiKey !== undefined, url });
|
|
44
|
+
// The handshake with the local client has to announce the remote's capabilities, so connect first.
|
|
45
|
+
// A failure here is not fatal: the next request tries again and reports what is wrong.
|
|
46
|
+
let remote;
|
|
47
|
+
let problem;
|
|
48
|
+
try {
|
|
49
|
+
remote = await connect();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
problem = explain(error);
|
|
53
|
+
}
|
|
54
|
+
const instructions = remote ? remote.getInstructions() : problem;
|
|
55
|
+
const server = new Server(remote?.getServerVersion() ?? { name: 'twitterviewer', title: 'TwitterViewer', version: VERSION }, {
|
|
56
|
+
capabilities: forwardableCapabilities(remote?.getServerCapabilities()),
|
|
57
|
+
...(instructions && { instructions }),
|
|
58
|
+
});
|
|
59
|
+
// `initialize` and `ping` are answered by the local server; everything else lands here.
|
|
60
|
+
server.fallbackRequestHandler = async (request, extra) => {
|
|
61
|
+
const progressToken = request.params?._meta?.progressToken;
|
|
62
|
+
try {
|
|
63
|
+
const client = await connect();
|
|
64
|
+
return await client.request({ method: request.method, params: request.params }, ResultSchema, {
|
|
65
|
+
signal: extra.signal,
|
|
66
|
+
timeout: requestTimeout,
|
|
67
|
+
...(progressToken !== undefined && {
|
|
68
|
+
onprogress: (progress) => {
|
|
69
|
+
void extra.sendNotification({ method: 'notifications/progress', params: { ...progress, progressToken } });
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
// A JSON-RPC error from the remote passes through with its code, message and data.
|
|
76
|
+
if (error instanceof McpError && error.code !== ErrorCode.RequestTimeout && error.code !== ErrorCode.ConnectionClosed) {
|
|
77
|
+
throw rpcError(error.code, error.message.replace(`MCP error ${error.code}: `, ''), error.data);
|
|
78
|
+
}
|
|
79
|
+
// Failed tool calls are returned as tool results so the model can read the reason.
|
|
80
|
+
if (request.method === 'tools/call')
|
|
81
|
+
return { content: [{ type: 'text', text: explain(error) }], isError: true };
|
|
82
|
+
throw rpcError(ErrorCode.InternalError, explain(error));
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
server.onclose = () => {
|
|
86
|
+
void upstream?.then((client) => client.close()).catch(() => { });
|
|
87
|
+
};
|
|
88
|
+
return server;
|
|
89
|
+
}
|
|
90
|
+
/** Drops what a request/response proxy cannot deliver: change notifications, subscriptions, logging and tasks. */
|
|
91
|
+
function forwardableCapabilities(remote) {
|
|
92
|
+
if (!remote)
|
|
93
|
+
return { tools: {} };
|
|
94
|
+
const { tools, resources, prompts, completions, experimental } = remote;
|
|
95
|
+
return {
|
|
96
|
+
...(tools && { tools: {} }),
|
|
97
|
+
...(resources && { resources: {} }),
|
|
98
|
+
...(prompts && { prompts: {} }),
|
|
99
|
+
...(completions && { completions }),
|
|
100
|
+
...(experimental && { experimental }),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** The SDK sends `code`, `message` and `data` of a thrown error as they are. `McpError` would prefix the message again. */
|
|
104
|
+
function rpcError(code, message, data) {
|
|
105
|
+
return Object.assign(new Error(message), { code, data });
|
|
106
|
+
}
|
|
107
|
+
function describeFailure(error, { hasKey, url }) {
|
|
108
|
+
if (error instanceof StreamableHTTPError) {
|
|
109
|
+
if (error.code === 401) {
|
|
110
|
+
return hasKey
|
|
111
|
+
? `TwitterViewer rejected the API key. Check TWITTERVIEWER_API_KEY or create a new key at ${API_KEY_URL} , then restart your MCP client.`
|
|
112
|
+
: `TWITTERVIEWER_API_KEY is not set. Create an API key (needs Plus) at ${API_KEY_URL} , add it to this server's environment and restart your MCP client.`;
|
|
113
|
+
}
|
|
114
|
+
const api = apiError(error.message);
|
|
115
|
+
if (error.code === 402 && api?.details?.reason === 'PLUS_REQUIRED') {
|
|
116
|
+
return `The account behind this API key does not have Plus, which the TwitterViewer MCP server requires. Subscribe at ${PRICING_URL} , then try again.`;
|
|
117
|
+
}
|
|
118
|
+
if (error.code === 429)
|
|
119
|
+
return `Too many requests. Retry in ${api?.retryAfterSec ?? 60} seconds.`;
|
|
120
|
+
return `The TwitterViewer MCP server returned an error (HTTP ${error.code})${api?.message ? `: ${api.message}` : '. Try again.'}`;
|
|
121
|
+
}
|
|
122
|
+
if (error instanceof McpError && error.code === ErrorCode.RequestTimeout) {
|
|
123
|
+
return 'The TwitterViewer MCP server did not answer in time. The request may still complete on the server, so check your credits before retrying.';
|
|
124
|
+
}
|
|
125
|
+
const cause = error instanceof Error ? (error.cause?.message ?? error.message) : String(error);
|
|
126
|
+
return `Could not reach ${url.href}: ${cause}`;
|
|
127
|
+
}
|
|
128
|
+
/** The SDK puts the HTTP response body at the end of its error message. */
|
|
129
|
+
function apiError(message) {
|
|
130
|
+
const start = message.indexOf('{');
|
|
131
|
+
if (start < 0)
|
|
132
|
+
return undefined;
|
|
133
|
+
try {
|
|
134
|
+
return JSON.parse(message.slice(start)).error;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "0.1.0";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = '0.1.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twitterviewer-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for reading public X (Twitter) posts, threads, profiles and replies as Markdown. Local stdio bridge to the hosted TwitterViewer MCP server.",
|
|
5
|
+
"mcpName": "io.github.TwitterViewer/twitterviewer",
|
|
6
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "twitter", "x", "twitter-mcp", "markdown", "thread", "ai-agents", "twitterviewer"],
|
|
7
|
+
"homepage": "https://twitterviewer.ai/twitterviewer-mcp-server",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/TwitterViewer/twitterviewer-mcp.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/TwitterViewer/twitterviewer-mcp/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/proxy.d.ts",
|
|
20
|
+
"default": "./dist/proxy.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"types": "./dist/proxy.d.ts",
|
|
25
|
+
"bin": {
|
|
26
|
+
"twitterviewer-mcp": "dist/bin.js"
|
|
27
|
+
},
|
|
28
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json && node -e \"require('node:fs').chmodSync('dist/bin.js', 0o755)\"",
|
|
34
|
+
"prepack": "npm run build",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
36
|
+
"test": "vitest run"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@modelcontextprotocol/sdk": "^1.32.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^20",
|
|
46
|
+
"typescript": "^5",
|
|
47
|
+
"vitest": "^3",
|
|
48
|
+
"zod": "^4"
|
|
49
|
+
}
|
|
50
|
+
}
|