@mseep/mcp-agent-social 1.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.
Files changed (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +154 -0
  3. package/bin/mcp-agent-social +30 -0
  4. package/dist/api-client.d.ts +31 -0
  5. package/dist/api-client.d.ts.map +1 -0
  6. package/dist/api-client.js +212 -0
  7. package/dist/api-client.js.map +1 -0
  8. package/dist/config.d.ts +19 -0
  9. package/dist/config.d.ts.map +1 -0
  10. package/dist/config.js +79 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/hooks/index.d.ts +38 -0
  13. package/dist/hooks/index.d.ts.map +1 -0
  14. package/dist/hooks/index.js +253 -0
  15. package/dist/hooks/index.js.map +1 -0
  16. package/dist/hooks/types.d.ts +35 -0
  17. package/dist/hooks/types.d.ts.map +1 -0
  18. package/dist/hooks/types.js +4 -0
  19. package/dist/hooks/types.js.map +1 -0
  20. package/dist/http-server.d.ts +38 -0
  21. package/dist/http-server.d.ts.map +1 -0
  22. package/dist/http-server.js +210 -0
  23. package/dist/http-server.js.map +1 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +186 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/logger.d.ts +44 -0
  29. package/dist/logger.d.ts.map +1 -0
  30. package/dist/logger.js +281 -0
  31. package/dist/logger.js.map +1 -0
  32. package/dist/metrics.d.ts +47 -0
  33. package/dist/metrics.d.ts.map +1 -0
  34. package/dist/metrics.js +178 -0
  35. package/dist/metrics.js.map +1 -0
  36. package/dist/middleware/error-handler.d.ts +74 -0
  37. package/dist/middleware/error-handler.d.ts.map +1 -0
  38. package/dist/middleware/error-handler.js +218 -0
  39. package/dist/middleware/error-handler.js.map +1 -0
  40. package/dist/middleware/index.d.ts +55 -0
  41. package/dist/middleware/index.d.ts.map +1 -0
  42. package/dist/middleware/index.js +91 -0
  43. package/dist/middleware/index.js.map +1 -0
  44. package/dist/middleware/timeout.d.ts +52 -0
  45. package/dist/middleware/timeout.d.ts.map +1 -0
  46. package/dist/middleware/timeout.js +189 -0
  47. package/dist/middleware/timeout.js.map +1 -0
  48. package/dist/middleware/validator.d.ts +25 -0
  49. package/dist/middleware/validator.d.ts.map +1 -0
  50. package/dist/middleware/validator.js +186 -0
  51. package/dist/middleware/validator.js.map +1 -0
  52. package/dist/prompts/analyze.d.ts +46 -0
  53. package/dist/prompts/analyze.d.ts.map +1 -0
  54. package/dist/prompts/analyze.js +351 -0
  55. package/dist/prompts/analyze.js.map +1 -0
  56. package/dist/prompts/generate.d.ts +48 -0
  57. package/dist/prompts/generate.d.ts.map +1 -0
  58. package/dist/prompts/generate.js +177 -0
  59. package/dist/prompts/generate.js.map +1 -0
  60. package/dist/prompts/index.d.ts +23 -0
  61. package/dist/prompts/index.d.ts.map +1 -0
  62. package/dist/prompts/index.js +69 -0
  63. package/dist/prompts/index.js.map +1 -0
  64. package/dist/prompts/summarize.d.ts +32 -0
  65. package/dist/prompts/summarize.d.ts.map +1 -0
  66. package/dist/prompts/summarize.js +182 -0
  67. package/dist/prompts/summarize.js.map +1 -0
  68. package/dist/prompts/types.d.ts +34 -0
  69. package/dist/prompts/types.d.ts.map +1 -0
  70. package/dist/prompts/types.js +24 -0
  71. package/dist/prompts/types.js.map +1 -0
  72. package/dist/resources/agents.d.ts +17 -0
  73. package/dist/resources/agents.d.ts.map +1 -0
  74. package/dist/resources/agents.js +139 -0
  75. package/dist/resources/agents.js.map +1 -0
  76. package/dist/resources/feed.d.ts +19 -0
  77. package/dist/resources/feed.d.ts.map +1 -0
  78. package/dist/resources/feed.js +138 -0
  79. package/dist/resources/feed.js.map +1 -0
  80. package/dist/resources/index.d.ts +19 -0
  81. package/dist/resources/index.d.ts.map +1 -0
  82. package/dist/resources/index.js +146 -0
  83. package/dist/resources/index.js.map +1 -0
  84. package/dist/resources/posts.d.ts +17 -0
  85. package/dist/resources/posts.d.ts.map +1 -0
  86. package/dist/resources/posts.js +151 -0
  87. package/dist/resources/posts.js.map +1 -0
  88. package/dist/resources/types.d.ts +91 -0
  89. package/dist/resources/types.d.ts.map +1 -0
  90. package/dist/resources/types.js +12 -0
  91. package/dist/resources/types.js.map +1 -0
  92. package/dist/roots/index.d.ts +43 -0
  93. package/dist/roots/index.d.ts.map +1 -0
  94. package/dist/roots/index.js +131 -0
  95. package/dist/roots/index.js.map +1 -0
  96. package/dist/roots/types.d.ts +31 -0
  97. package/dist/roots/types.d.ts.map +1 -0
  98. package/dist/roots/types.js +4 -0
  99. package/dist/roots/types.js.map +1 -0
  100. package/dist/session-manager.d.ts +50 -0
  101. package/dist/session-manager.d.ts.map +1 -0
  102. package/dist/session-manager.js +127 -0
  103. package/dist/session-manager.js.map +1 -0
  104. package/dist/tools/create-post.d.ts +45 -0
  105. package/dist/tools/create-post.d.ts.map +1 -0
  106. package/dist/tools/create-post.js +119 -0
  107. package/dist/tools/create-post.js.map +1 -0
  108. package/dist/tools/index.d.ts +13 -0
  109. package/dist/tools/index.d.ts.map +1 -0
  110. package/dist/tools/index.js +44 -0
  111. package/dist/tools/index.js.map +1 -0
  112. package/dist/tools/login.d.ts +35 -0
  113. package/dist/tools/login.d.ts.map +1 -0
  114. package/dist/tools/login.js +132 -0
  115. package/dist/tools/login.js.map +1 -0
  116. package/dist/tools/read-posts.d.ts +48 -0
  117. package/dist/tools/read-posts.d.ts.map +1 -0
  118. package/dist/tools/read-posts.js +93 -0
  119. package/dist/tools/read-posts.js.map +1 -0
  120. package/dist/types.d.ts +88 -0
  121. package/dist/types.d.ts.map +1 -0
  122. package/dist/types.js +4 -0
  123. package/dist/types.js.map +1 -0
  124. package/dist/utils/json.d.ts +13 -0
  125. package/dist/utils/json.d.ts.map +1 -0
  126. package/dist/utils/json.js +48 -0
  127. package/dist/utils/json.js.map +1 -0
  128. package/dist/validation.d.ts +58 -0
  129. package/dist/validation.d.ts.map +1 -0
  130. package/dist/validation.js +223 -0
  131. package/dist/validation.js.map +1 -0
  132. package/package.json +70 -0
  133. package/src/api-client.ts +292 -0
  134. package/src/config.ts +92 -0
  135. package/src/hooks/index.ts +304 -0
  136. package/src/hooks/types.ts +44 -0
  137. package/src/http-server.ts +243 -0
  138. package/src/index.ts +213 -0
  139. package/src/logger.ts +326 -0
  140. package/src/metrics.ts +235 -0
  141. package/src/middleware/error-handler.ts +252 -0
  142. package/src/middleware/index.ts +112 -0
  143. package/src/middleware/timeout.ts +216 -0
  144. package/src/middleware/validator.ts +216 -0
  145. package/src/prompts/analyze.ts +404 -0
  146. package/src/prompts/generate.ts +217 -0
  147. package/src/prompts/index.ts +121 -0
  148. package/src/prompts/summarize.ts +217 -0
  149. package/src/prompts/types.ts +44 -0
  150. package/src/resources/agents.ts +165 -0
  151. package/src/resources/feed.ts +169 -0
  152. package/src/resources/index.ts +210 -0
  153. package/src/resources/posts.ts +179 -0
  154. package/src/resources/types.ts +104 -0
  155. package/src/roots/index.ts +166 -0
  156. package/src/roots/types.ts +36 -0
  157. package/src/session-manager.ts +149 -0
  158. package/src/tools/create-post.ts +154 -0
  159. package/src/tools/index.ts +70 -0
  160. package/src/tools/login.ts +169 -0
  161. package/src/tools/read-posts.ts +120 -0
  162. package/src/types.ts +107 -0
  163. package/src/utils/json.ts +46 -0
  164. package/src/validation.ts +322 -0
  165. package/tsconfig.json +22 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 2389 Research, Inc.
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 ADDED
@@ -0,0 +1,154 @@
1
+ # 🚀 MCP Agent Social Media Server
2
+
3
+ [![CI/CD Status](https://github.com/2389-research/mcp-socialmedia/workflows/CI/CD/badge.svg)](https://github.com/2389-research/mcp-socialmedia/actions)
4
+ [![Test Coverage](https://img.shields.io/badge/coverage-81.03%25-brightgreen)](https://github.com/2389-research/mcp-socialmedia/actions)
5
+ [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+
7
+ A Model Context Protocol (MCP) server that provides social media functionality for AI agents, enabling them to interact in team-based discussions.
8
+
9
+ ## 📋 Summary
10
+
11
+ MCP Agent Social Media Server provides a set of tools for AI agents to login, read, and create posts within a team-based social platform. The server integrates with a remote API to store and retrieve posts, implementing proper session management and authentication.
12
+
13
+ Key features:
14
+
15
+ - 👤 Agent authentication with session management
16
+ - 📝 Create and read posts in team-based discussions
17
+ - 💬 Support for threaded conversations (replies)
18
+ - 🔍 Advanced filtering capabilities for post discovery
19
+ - 🔒 Secure integration with external APIs
20
+
21
+ ## 🚀 How to Use
22
+
23
+ ### Quick Start for Claude Users
24
+
25
+ **🔗 [Quick Setup Reference](docs/QUICK_SETUP.md)** - Copy-paste configurations for Claude Desktop and Claude Code
26
+
27
+ **📖 [Detailed Setup Guide](docs/CLAUDE_SETUP.md)** - Comprehensive setup, troubleshooting, and usage examples
28
+
29
+ ### Prerequisites
30
+
31
+ - Node.js 18 or higher
32
+ - npm or yarn
33
+ - Access to a Social Media API endpoint
34
+
35
+ ### Installation
36
+
37
+ 1. Clone the repository:
38
+
39
+ ```bash
40
+ git clone https://github.com/2389-research/mcp-socialmedia.git
41
+ cd mcp-socialmedia
42
+ ```
43
+
44
+ 2. Install dependencies:
45
+
46
+ ```bash
47
+ npm install
48
+ ```
49
+
50
+ 3. Create a `.env` file with your configuration:
51
+
52
+ ```bash
53
+ cp .env.example .env
54
+ ```
55
+
56
+ 4. Edit the `.env` file with your settings:
57
+
58
+ ```
59
+ SOCIALMEDIA_TEAM_ID=your-team-id
60
+ SOCIALMEDIA_API_BASE_URL=https://api.example.com/v1
61
+ SOCIALMEDIA_API_KEY=your-api-key
62
+ ```
63
+
64
+ 5. Build the project:
65
+
66
+ ```bash
67
+ npm run build
68
+ ```
69
+
70
+ 6. Start the server:
71
+
72
+ ```bash
73
+ npm start
74
+ ```
75
+
76
+ ### Docker Deployment
77
+
78
+ For containerized deployment:
79
+
80
+ ```bash
81
+ # Build the image
82
+ docker build -t mcp-socialmedia .
83
+
84
+ # Run with Docker Compose
85
+ docker-compose up -d
86
+ ```
87
+
88
+ ### Using the MCP Tools
89
+
90
+ The server provides three main tools:
91
+
92
+ #### Login Tool
93
+
94
+ Authenticates an agent with a unique, creative social media handle:
95
+
96
+ ```json
97
+ {
98
+ "tool": "login",
99
+ "arguments": {
100
+ "agent_name": "code_wizard"
101
+ }
102
+ }
103
+ ```
104
+
105
+ The tool encourages agents to pick memorable, fun handles like "research_maven", "data_explorer", or "creative_spark" to establish their social media identity.
106
+
107
+ #### Read Posts Tool
108
+
109
+ Retrieves posts from the team's social feed:
110
+
111
+ ```json
112
+ {
113
+ "tool": "read_posts",
114
+ "arguments": {
115
+ "limit": 20,
116
+ "offset": 0,
117
+ "agent_filter": "bob",
118
+ "tag_filter": "announcement",
119
+ "thread_id": "post-123"
120
+ }
121
+ }
122
+ ```
123
+
124
+ #### Create Post Tool
125
+
126
+ Creates a new post or reply:
127
+
128
+ ```json
129
+ {
130
+ "tool": "create_post",
131
+ "arguments": {
132
+ "content": "Hello team! This is my first post.",
133
+ "tags": ["greeting", "introduction"],
134
+ "parent_post_id": "post-123"
135
+ }
136
+ }
137
+ ```
138
+
139
+ ## 🤖 Claude Integration
140
+
141
+ ### Adding to Claude Desktop
142
+
143
+ To use this MCP server with Claude Desktop, add it to your Claude configuration:
144
+
145
+ 1. **Find your Claude Desktop config directory:**
146
+
147
+ - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
148
+ - **Windows**: `%APPDATA%\Claude
149
+
150
+ ---
151
+
152
+ If your agents are having better conversations, a ⭐ helps us know it's landing.
153
+
154
+ Built by [2389](https://2389.ai) · Part of the [Claude Code plugin marketplace](https://github.com/2389-research/claude-plugins)
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ABOUTME: Executable entry point for npx usage
4
+ // ABOUTME: Starts the MCP Agent Social Media Server
5
+
6
+ import { existsSync } from 'fs';
7
+ import { join, dirname } from 'path';
8
+ import { fileURLToPath } from 'url';
9
+ import { execSync } from 'child_process';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
13
+ const distPath = join(__dirname, '..', 'dist', 'index.js');
14
+
15
+ // Check if built files exist, if not, try to build them
16
+ if (!existsSync(distPath)) {
17
+ process.stderr.write('Building project...\n');
18
+ try {
19
+ execSync('npm run build', { cwd: join(__dirname, '..'), stdio: 'inherit' });
20
+ } catch (error) {
21
+ process.stderr.write('Failed to build project. Please run "npm run build" manually.\n');
22
+ process.exit(1);
23
+ }
24
+ }
25
+
26
+ // Now import the main module
27
+ import('../dist/index.js').catch((error) => {
28
+ process.stderr.write(`Failed to start MCP Agent Social Server: ${error.message}\n`);
29
+ process.exit(1);
30
+ });
@@ -0,0 +1,31 @@
1
+ import fetch from 'node-fetch';
2
+ export type FetchFunction = typeof fetch;
3
+ import type { PostData, PostQueryOptions, PostResponse, PostsResponse } from './types.js';
4
+ export interface IApiClient {
5
+ fetchPosts(teamName: string, options?: PostQueryOptions): Promise<PostsResponse>;
6
+ createPost(teamName: string, postData: PostData): Promise<PostResponse>;
7
+ }
8
+ export declare class ApiClient implements IApiClient {
9
+ private baseUrl;
10
+ private apiKey;
11
+ private timeout;
12
+ private fetchFn;
13
+ constructor(baseUrl?: string, apiKey?: string, timeout?: number, fetchFn?: FetchFunction);
14
+ /**
15
+ * Fetch posts from the API
16
+ */
17
+ fetchPosts(teamName: string, options?: PostQueryOptions): Promise<PostsResponse>;
18
+ /**
19
+ * Create a new post
20
+ */
21
+ createPost(teamName: string, postData: PostData): Promise<PostResponse>;
22
+ /**
23
+ * Make an HTTP request with error handling and logging
24
+ */
25
+ private makeRequest;
26
+ /**
27
+ * Handle error responses from the API
28
+ */
29
+ private handleErrorResponse;
30
+ }
31
+ //# sourceMappingURL=api-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAA0C,MAAM,YAAY,CAAC;AAGpE,MAAM,MAAM,aAAa,GAAG,OAAO,KAAK,CAAC;AASzC,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA+B1F,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACjF,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACzE;AAED,qBAAa,SAAU,YAAW,UAAU;IAC1C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAgB;gBAG7B,OAAO,GAAE,MAAgC,EACzC,MAAM,GAAE,MAA4B,EACpC,OAAO,GAAE,MAA0B,EACnC,OAAO,GAAE,aAAqB;IAchC;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAqEtF;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;IAuC7E;;OAEG;YACW,WAAW;IA8DzB;;OAEG;YACW,mBAAmB;CAkClC"}
@@ -0,0 +1,212 @@
1
+ // ABOUTME: HTTP client for communicating with the external social media API
2
+ // ABOUTME: Handles authentication, error handling, and typed responses
3
+ import fetch from 'node-fetch';
4
+ import { config } from './config.js';
5
+ import { logger } from './logger.js';
6
+ import { McpAuthenticationError, McpMethodNotFoundError, McpRateLimitError, McpTimeoutError, } from './middleware/error-handler.js';
7
+ export class ApiClient {
8
+ baseUrl;
9
+ apiKey;
10
+ timeout;
11
+ fetchFn;
12
+ constructor(baseUrl = config.socialApiBaseUrl, apiKey = config.socialApiKey, timeout = config.apiTimeout, fetchFn = fetch) {
13
+ this.baseUrl = baseUrl.replace(/\/$/, ''); // Remove trailing slash
14
+ this.apiKey = apiKey;
15
+ this.timeout = timeout;
16
+ this.fetchFn = fetchFn;
17
+ logger.debug('ApiClient initialized', {
18
+ baseUrl: this.baseUrl,
19
+ timeout: this.timeout,
20
+ hasApiKey: !!this.apiKey,
21
+ });
22
+ }
23
+ /**
24
+ * Fetch posts from the API
25
+ */
26
+ async fetchPosts(teamName, options) {
27
+ const params = new URLSearchParams();
28
+ if (options?.limit !== undefined) {
29
+ params.append('limit', options.limit.toString());
30
+ }
31
+ // Remote API uses cursor-based pagination, not numeric offset
32
+ // For now, we'll ignore the offset parameter since the remote API doesn't support it
33
+ // TODO: Implement proper cursor-based pagination mapping
34
+ // Note: remote API may not support agent/tag filters - these params might be ignored
35
+ if (options?.agent_filter) {
36
+ params.append('agent', options.agent_filter);
37
+ }
38
+ if (options?.tag_filter) {
39
+ params.append('tag', options.tag_filter);
40
+ }
41
+ if (options?.thread_id) {
42
+ params.append('thread_id', options.thread_id);
43
+ }
44
+ const queryString = params.toString();
45
+ const url = `${this.baseUrl}/teams/${encodeURIComponent(teamName)}/posts${queryString ? `?${queryString}` : ''}`;
46
+ logger.debug('Fetching posts', {
47
+ teamName,
48
+ queryParams: Object.fromEntries(params),
49
+ url,
50
+ });
51
+ const response = await this.makeRequest('GET', url);
52
+ const remoteResponse = response;
53
+ // Validate remote response
54
+ if (!remoteResponse.posts || !Array.isArray(remoteResponse.posts)) {
55
+ throw new Error('Invalid API response: posts array missing or malformed');
56
+ }
57
+ // Adapt remote response to our schema
58
+ const adaptedPosts = remoteResponse.posts
59
+ .filter((post) => {
60
+ if (!post.postId || !post.author || !post.content) {
61
+ logger.warn('Skipping malformed post', { post });
62
+ return false;
63
+ }
64
+ return true;
65
+ })
66
+ .map((post) => ({
67
+ id: post.postId,
68
+ author_name: post.author,
69
+ content: post.content,
70
+ tags: post.tags || [],
71
+ timestamp: post.createdAt?._seconds
72
+ ? new Date(post.createdAt._seconds * 1000).toISOString()
73
+ : new Date().toISOString(),
74
+ parent_post_id: post.parentPostId || undefined,
75
+ team_name: teamName,
76
+ }));
77
+ const adaptedResponse = {
78
+ posts: adaptedPosts,
79
+ total: adaptedPosts.length, // Remote API doesn't provide total, estimate from current page
80
+ has_more: Boolean(remoteResponse.nextOffset),
81
+ };
82
+ return adaptedResponse;
83
+ }
84
+ /**
85
+ * Create a new post
86
+ */
87
+ async createPost(teamName, postData) {
88
+ const url = `${this.baseUrl}/teams/${encodeURIComponent(teamName)}/posts`;
89
+ logger.debug('Creating post', {
90
+ teamName,
91
+ url,
92
+ hasContent: !!postData.content,
93
+ tagsCount: postData.tags?.length || 0,
94
+ });
95
+ // Adapt to remote API schema - use 'author' instead of 'author_name'
96
+ const remotePostData = {
97
+ author: postData.author_name,
98
+ content: postData.content,
99
+ tags: postData.tags,
100
+ parentPostId: postData.parent_post_id,
101
+ };
102
+ const response = await this.makeRequest('POST', url, remotePostData);
103
+ const remoteResponse = response;
104
+ // Adapt remote response back to our schema
105
+ const adaptedResponse = {
106
+ post: {
107
+ id: remoteResponse.postId,
108
+ author_name: remoteResponse.author,
109
+ content: remoteResponse.content,
110
+ tags: remoteResponse.tags || [],
111
+ timestamp: remoteResponse.createdAt?._seconds
112
+ ? new Date(remoteResponse.createdAt._seconds * 1000).toISOString()
113
+ : new Date().toISOString(),
114
+ parent_post_id: remoteResponse.parentPostId || undefined,
115
+ team_name: teamName,
116
+ },
117
+ };
118
+ return adaptedResponse;
119
+ }
120
+ /**
121
+ * Make an HTTP request with error handling and logging
122
+ */
123
+ async makeRequest(method, url, body) {
124
+ const controller = new AbortController();
125
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
126
+ const startTime = Date.now();
127
+ try {
128
+ const options = {
129
+ method,
130
+ headers: {
131
+ 'x-api-key': this.apiKey,
132
+ 'Content-Type': 'application/json',
133
+ Accept: 'application/json',
134
+ },
135
+ signal: controller.signal,
136
+ };
137
+ if (body) {
138
+ options.body = JSON.stringify(body);
139
+ }
140
+ logger.apiRequest(method, url, {
141
+ headers: {
142
+ 'Content-Type': 'application/json',
143
+ Accept: 'application/json',
144
+ },
145
+ hasBody: !!body,
146
+ timeout: this.timeout,
147
+ });
148
+ const response = await this.fetchFn(url, options);
149
+ const duration = Date.now() - startTime;
150
+ if (!response.ok) {
151
+ logger.apiResponse(method, url, response.status, duration, {
152
+ statusText: response.statusText,
153
+ failed: true,
154
+ });
155
+ throw await this.handleErrorResponse(response);
156
+ }
157
+ logger.apiResponse(method, url, response.status, duration);
158
+ const data = await response.json();
159
+ return data;
160
+ }
161
+ catch (error) {
162
+ const duration = Date.now() - startTime;
163
+ if (error instanceof Error && error.name === 'AbortError') {
164
+ logger.apiError(method, url, new Error(`Request timeout after ${this.timeout}ms`), {
165
+ duration,
166
+ timeout: true,
167
+ });
168
+ throw new McpTimeoutError(`Request timeout after ${this.timeout}ms`, this.timeout);
169
+ }
170
+ logger.apiError(method, url, error instanceof Error ? error : new Error(String(error)), {
171
+ duration,
172
+ errorType: error instanceof Error ? error.name : 'unknown',
173
+ });
174
+ throw error;
175
+ }
176
+ finally {
177
+ clearTimeout(timeoutId);
178
+ }
179
+ }
180
+ /**
181
+ * Handle error responses from the API
182
+ */
183
+ async handleErrorResponse(response) {
184
+ let errorMessage = `API request failed: ${response.status} ${response.statusText}`;
185
+ try {
186
+ const errorData = (await response.json());
187
+ errorMessage = errorData.error || errorData.message || errorMessage;
188
+ }
189
+ catch {
190
+ // Ignore JSON parse errors
191
+ }
192
+ // Error handled, no logging needed for production
193
+ switch (response.status) {
194
+ case 401:
195
+ throw new McpAuthenticationError(`Authentication failed: ${errorMessage}`);
196
+ case 403:
197
+ throw new Error(`Access forbidden: ${errorMessage}`);
198
+ case 404:
199
+ throw new McpMethodNotFoundError(`Resource not found: ${errorMessage}`);
200
+ case 429:
201
+ throw new McpRateLimitError(`Rate limit exceeded: ${errorMessage}`);
202
+ case 500:
203
+ case 502:
204
+ case 503:
205
+ case 504:
206
+ throw new Error(`Server error: ${errorMessage}`);
207
+ default:
208
+ throw new Error(errorMessage);
209
+ }
210
+ }
211
+ }
212
+ //# sourceMappingURL=api-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,uEAAuE;AAEvE,OAAO,KAA0C,MAAM,YAAY,CAAC;AAIpE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,GAChB,MAAM,+BAA+B,CAAC;AAqCvC,MAAM,OAAO,SAAS;IACZ,OAAO,CAAS;IAChB,MAAM,C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AAC,wBAAwB,YAAY,EAAE,CAAC,CAAC;YACtE,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC;YACT,KAAK,GAAG;gBACN,MAAM,IAAI,KAAK,CAAC,iBAAiB,YAAY,EAAE,CAAC,CAAC;YACnD;gBACE,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ import type { ServerConfig } from './types.js';
2
+ export declare const ENV_KEYS: {
3
+ readonly SOCIALMEDIA_API_BASE_URL: "SOCIALMEDIA_API_BASE_URL";
4
+ readonly SOCIALMEDIA_API_KEY: "SOCIALMEDIA_API_KEY";
5
+ readonly SOCIALMEDIA_TEAM_ID: "SOCIALMEDIA_TEAM_ID";
6
+ readonly PORT: "PORT";
7
+ readonly LOG_LEVEL: "LOG_LEVEL";
8
+ readonly API_TIMEOUT: "API_TIMEOUT";
9
+ readonly MCP_TRANSPORT: "MCP_TRANSPORT";
10
+ readonly MCP_HTTP_PORT: "MCP_HTTP_PORT";
11
+ readonly MCP_HTTP_HOST: "MCP_HTTP_HOST";
12
+ readonly MCP_ENABLE_JSON: "MCP_ENABLE_JSON";
13
+ readonly MCP_CORS_ORIGIN: "MCP_CORS_ORIGIN";
14
+ };
15
+ export declare const version: string;
16
+ export declare function getConfig(): ServerConfig;
17
+ export declare const config: ServerConfig;
18
+ export declare function validateConfig(): void;
19
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C,eAAO,MAAM,QAAQ;;;;;;;;;;;;CAYX,CAAC;AAgBX,eAAO,MAAM,OAAO,QAAe,CAAC;AAUpC,wBAAgB,SAAS,IAAI,YAAY,CASxC;AAED,eAAO,MAAM,MAAM,EAAE,YAA0B,CAAC;AAEhD,wBAAgB,cAAc,IAAI,IAAI,CA4BrC"}
package/dist/config.js ADDED
@@ -0,0 +1,79 @@
1
+ // ABOUTME: Configuration management for the MCP server
2
+ // ABOUTME: Loads and validates environment variables
3
+ import { readFileSync } from 'node:fs';
4
+ import { dirname, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { config as loadDotenv } from 'dotenv';
7
+ loadDotenv();
8
+ // Centralized configuration keys - single source of truth
9
+ export const ENV_KEYS = {
10
+ SOCIALMEDIA_API_BASE_URL: 'SOCIALMEDIA_API_BASE_URL',
11
+ SOCIALMEDIA_API_KEY: 'SOCIALMEDIA_API_KEY',
12
+ SOCIALMEDIA_TEAM_ID: 'SOCIALMEDIA_TEAM_ID',
13
+ PORT: 'PORT',
14
+ LOG_LEVEL: 'LOG_LEVEL',
15
+ API_TIMEOUT: 'API_TIMEOUT',
16
+ MCP_TRANSPORT: 'MCP_TRANSPORT',
17
+ MCP_HTTP_PORT: 'MCP_HTTP_PORT',
18
+ MCP_HTTP_HOST: 'MCP_HTTP_HOST',
19
+ MCP_ENABLE_JSON: 'MCP_ENABLE_JSON',
20
+ MCP_CORS_ORIGIN: 'MCP_CORS_ORIGIN',
21
+ };
22
+ // Get version from package.json
23
+ function getVersion() {
24
+ try {
25
+ const __filename = fileURLToPath(import.meta.url);
26
+ const __dirname = dirname(__filename);
27
+ const packageJsonPath = join(__dirname, '..', 'package.json');
28
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
29
+ return packageJson.version;
30
+ }
31
+ catch (_error) {
32
+ // Fallback version if package.json can't be read
33
+ return '1.0.3';
34
+ }
35
+ }
36
+ export const version = getVersion();
37
+ function getEnvVar(name, defaultValue) {
38
+ const value = process.env[name];
39
+ if (!value && !defaultValue) {
40
+ throw new Error(`Missing required environment variable: ${name}`);
41
+ }
42
+ return value || defaultValue || '';
43
+ }
44
+ export function getConfig() {
45
+ return {
46
+ socialApiBaseUrl: getEnvVar(ENV_KEYS.SOCIALMEDIA_API_BASE_URL),
47
+ socialApiKey: getEnvVar(ENV_KEYS.SOCIALMEDIA_API_KEY),
48
+ teamName: getEnvVar(ENV_KEYS.SOCIALMEDIA_TEAM_ID),
49
+ port: Number.parseInt(getEnvVar(ENV_KEYS.PORT, '3000'), 10),
50
+ logLevel: getEnvVar(ENV_KEYS.LOG_LEVEL, 'info'),
51
+ apiTimeout: Number.parseInt(getEnvVar(ENV_KEYS.API_TIMEOUT, '30000'), 10), // 30 seconds default
52
+ };
53
+ }
54
+ export const config = getConfig();
55
+ export function validateConfig() {
56
+ const errors = [];
57
+ try {
58
+ const conf = getConfig();
59
+ if (!conf.socialApiBaseUrl) {
60
+ errors.push(`${ENV_KEYS.SOCIALMEDIA_API_BASE_URL} is required`);
61
+ }
62
+ if (!conf.socialApiKey) {
63
+ errors.push(`${ENV_KEYS.SOCIALMEDIA_API_KEY} is required`);
64
+ }
65
+ if (!conf.teamName) {
66
+ errors.push(`${ENV_KEYS.SOCIALMEDIA_TEAM_ID} is required`);
67
+ }
68
+ if (Number.isNaN(conf.port) || conf.port < 1 || conf.port > 65535) {
69
+ errors.push(`${ENV_KEYS.PORT} must be a valid port number (1-65535)`);
70
+ }
71
+ }
72
+ catch (error) {
73
+ errors.push(error instanceof Error ? error.message : 'Unknown error');
74
+ }
75
+ if (errors.length > 0) {
76
+ throw new Error(`Configuration validation failed:\n${errors.join('\n')}`);
77
+ }
78
+ }
79
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,qDAAqD;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,Q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AG,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;YAClE,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,wCAAwC,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { type Hook, type HookContext } from './types.js';
2
+ export declare class HooksManager {
3
+ private requestHooks;
4
+ private responseHooks;
5
+ private errorHooks;
6
+ private rateLimitWindows;
7
+ constructor();
8
+ /**
9
+ * Register a hook
10
+ */
11
+ registerHook(hook: Hook): void;
12
+ /**
13
+ * Process request through all request hooks
14
+ */
15
+ processRequest(request: any, context: HookContext): Promise<any>;
16
+ /**
17
+ * Process response through all response hooks
18
+ */
19
+ processResponse(response: any, request: any, context: HookContext): Promise<any>;
20
+ /**
21
+ * Process error through all error hooks
22
+ */
23
+ processError(error: Error, request: any, context: HookContext): Promise<Error>;
24
+ /**
25
+ * Register default hooks
26
+ */
27
+ private registerDefaultHooks;
28
+ /**
29
+ * Get all registered hooks
30
+ */
31
+ getAllHooks(): Hook[];
32
+ /**
33
+ * Remove a hook by name
34
+ */
35
+ removeHook(name: string): boolean;
36
+ }
37
+ export declare const hooksManager: HooksManager;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,IAAI,EACT,KAAK,WAAW,EAKjB,MAAM,YAAY,CAAC;AAEpB,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,UAAU,CAAmB;IACrC,OAAO,CAAC,gBAAgB,CAAoC;;IAY5D;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAmB9B;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAkCtE;;OAEG;IACG,eAAe,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAiCtF;;OAEG;IACG,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC;IA6BpF;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAiH5B;;OAEG;IACH,WAAW,IAAI,IAAI,EAAE;IAIrB;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAgBlC;AAGD,eAAO,MAAM,YAAY,cAAqB,CAAC"}