-
Notifications
You must be signed in to change notification settings - Fork 0
Add ChatGPT MCP Connector Compatibility #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
encryptedDegen
wants to merge
8
commits into
main
Choose a base branch
from
chatgpt-compatibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
56fff1b
Add ChatGPT compatibility tools
encryptedDegen 636a35f
Register ChatGPT compatibility tools in main index
encryptedDegen 91b7c20
Update README with ChatGPT compatibility documentation
encryptedDegen 6895811
Update src/tools/chatgpt.ts
encryptedDegen 7f390b7
Update src/tools/chatgpt.ts
encryptedDegen 4e2a35a
Update src/tools/chatgpt.ts
encryptedDegen 6294bb2
Update src/tools/chatgpt.ts
encryptedDegen c6b44fe
fixes
encryptedDegen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export const FETCH_LIMIT = 20; | ||
|
|
||
| export const ETH_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| import { z } from 'zod'; | ||
| import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; | ||
| import { StatsResponse, AccountResponse, LeaderboardResponse } from '../types/api'; | ||
| import { ETH_ADDRESS_REGEX, FETCH_LIMIT } from '../const'; | ||
|
|
||
| // Types for ChatGPT search/fetch pattern | ||
| interface SearchResult { | ||
| id: string; | ||
| title: string; | ||
| description: string; | ||
| type: 'profile' | 'follower' | 'following' | 'list'; | ||
| } | ||
|
|
||
| interface ProfileRecord { | ||
| id: string; | ||
| address: string; | ||
| ens?: string; | ||
| followerCount: number; | ||
| followingCount: number; | ||
| tags?: string[]; | ||
| lists?: any[]; | ||
| metadata?: any; | ||
| } | ||
|
|
||
| export function registerChatGPTTools(server: McpServer, baseUrl: string, ensWorkerUrl: string) { | ||
| // Search tool - required by ChatGPT | ||
| server.tool( | ||
| 'search', | ||
| 'Search for Ethereum addresses, ENS names, or profiles in the EFP ecosystem. Returns IDs that can be fetched for detailed information.', | ||
| { | ||
| query: z.string().describe('Search query - can be an ENS name, Ethereum address, or general search term for profiles'), | ||
| limit: z.number().optional().default(10).describe('Maximum number of results to return (default: 10)'), | ||
| type: z.enum(['profile', 'follower', 'following', 'all']).optional().default('all').describe('Type of search to perform'), | ||
| }, | ||
| async ({ query, limit = 10, type = 'all' }) => { | ||
| try { | ||
| const results: SearchResult[] = []; | ||
|
|
||
| // If query looks like an address or ENS name, search for exact match first | ||
| if (query.includes('.eth') || ETH_ADDRESS_REGEX.test(query)) { | ||
| try { | ||
| const statsResponse = await fetch(`${baseUrl}/users/${encodeURIComponent(query)}/stats`); | ||
| if (statsResponse.ok) { | ||
| const stats = (await statsResponse.json()) as StatsResponse; | ||
| const accountResponse = await fetch(`${baseUrl}/users/${encodeURIComponent(query)}/account`); | ||
| const account = accountResponse.ok ? ((await accountResponse.json()) as AccountResponse) : null; | ||
|
|
||
| results.push({ | ||
| id: `profile:${query}`, | ||
| title: account?.ens?.name || query, | ||
| description: `Profile with ${stats.followers_count || 0} followers and following ${stats.following_count || 0} accounts`, | ||
| type: 'profile', | ||
| }); | ||
| } | ||
| } catch (e) { | ||
| // Profile not found, continue with other searches | ||
| console.error('Error fetching profile in search tool:', e); | ||
| } | ||
| } | ||
|
|
||
| // Search for popular profiles in leaderboard | ||
| if ((type === 'follower' || type === 'all') && results.length < limit) { | ||
| try { | ||
| const lowerQuery = query.toLowerCase(); | ||
| const leaderboardResponse = await fetch(`${baseUrl}/discover/leaderboard?limit=${Math.min(FETCH_LIMIT, limit * 2)}`); | ||
| if (leaderboardResponse.ok) { | ||
| const leaderboard = (await leaderboardResponse.json()) as LeaderboardResponse; | ||
| if (leaderboard.results) { | ||
| for (const account of leaderboard.results) { | ||
| const name = account.ens?.name || account.address; | ||
| if (name.toLowerCase().includes(lowerQuery) && results.length < limit) { | ||
| results.push({ | ||
| id: `profile:${account.address}`, | ||
| title: name, | ||
| description: `Popular profile with ${account.followers_count || 0} followers`, | ||
| type: 'profile', | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } catch (e) { | ||
| console.error('Leaderboard search failed:', e); | ||
| } | ||
| } | ||
|
|
||
| // If no results found, provide helpful suggestions | ||
| if (results.length === 0) { | ||
| results.push({ | ||
| id: 'help:search', | ||
| title: 'Search Help', | ||
| description: 'Try searching with an ENS name (e.g., vitalik.eth) or Ethereum address', | ||
| type: 'profile', | ||
| }); | ||
| } | ||
|
|
||
| return { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: JSON.stringify({ | ||
| ids: results.map((r) => r.id), | ||
| results: results, | ||
| }), | ||
| }, | ||
| ], | ||
| }; | ||
| } catch (error) { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: JSON.stringify({ | ||
| ids: [], | ||
| error: error instanceof Error ? error.message : 'Unknown error', | ||
| }), | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| // Fetch tool - required by ChatGPT | ||
| server.tool( | ||
| 'fetch', | ||
| 'Fetch detailed information for a specific ID returned by the search tool.', | ||
| { | ||
| id: z.string().describe('ID returned from search results (format: type:identifier)'), | ||
| }, | ||
| async ({ id }) => { | ||
| try { | ||
| const [type, identifier] = id.split(':', 2); | ||
|
|
||
| if (type === 'help') { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: JSON.stringify({ | ||
| title: 'EFP Search Help', | ||
| content: 'Search with ENS names like vitalik.eth or Ethereum addresses', | ||
| type: 'help', | ||
| }), | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| if (type === 'profile') { | ||
| const profileData: ProfileRecord = { | ||
| id: id, | ||
| address: identifier, | ||
| followerCount: 0, | ||
| followingCount: 0, | ||
| }; | ||
|
|
||
| // Get basic stats | ||
| try { | ||
| const statsResponse = await fetch(`${baseUrl}/users/${encodeURIComponent(identifier)}/stats`); | ||
| if (statsResponse.ok) { | ||
| const stats = (await statsResponse.json()) as StatsResponse; | ||
| profileData.followerCount = stats.followers_count || 0; | ||
| profileData.followingCount = stats.following_count || 0; | ||
| } | ||
| } catch (e) { | ||
| console.error('Error fetching user stats:', e); | ||
| } | ||
|
|
||
| // Get account details | ||
| try { | ||
| const accountResponse = await fetch(`${baseUrl}/users/${encodeURIComponent(identifier)}/account`); | ||
| if (accountResponse.ok) { | ||
| const account = (await accountResponse.json()) as AccountResponse; | ||
| profileData.ens = account.ens?.name; | ||
| profileData.metadata = { | ||
| avatar: account.ens?.avatar, | ||
| description: account.ens?.contenthash, | ||
| twitter: account.ens?.records?.['com.twitter'], | ||
| github: account.ens?.records?.['com.github'], | ||
| discord: account.ens?.records?.['com.discord'], | ||
| telegram: account.ens?.records?.['org.telegram'], | ||
| website: account.ens?.records?.url, | ||
| }; | ||
| } | ||
| } catch (e) { | ||
| console.error('Error fetching account details for profile:', identifier, e); | ||
| } | ||
|
|
||
| return { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: JSON.stringify(profileData, null, 2), | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: JSON.stringify({ | ||
| error: `Unknown ID format: ${id}`, | ||
| }), | ||
| }, | ||
| ], | ||
| }; | ||
| } catch (error) { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: JSON.stringify({ | ||
| error: error instanceof Error ? error.message : 'Unknown error', | ||
| id: id, | ||
| }), | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| } | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.