Skip to content

Commit 0963d00

Browse files
Merge pull request #8 from IQAIcom/fix-add-wiki-search-tool-to-get-answers-and-search-with-natural-language
2 parents 669cf10 + 9036d88 commit 0963d00

File tree

8 files changed

+140
-5
lines changed

8 files changed

+140
-5
lines changed

.changeset/grumpy-sites-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@iqai/mcp-iqwiki": patch
3+
---
4+
5+
Adds wiki search tool ot get answers and search with natural language

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
33
"files": {
4-
"ignore": ["node_modules/**", "dist/**"]
4+
"ignore": ["node_modules/**", "dist/**", "src/graphql-env.d.ts"]
55
},
66
"linter": {
77
"enabled": true,

src/graphql-env.d.ts

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,14 @@ export type introspection_types = {
614614
ofType: { kind: "SCALAR"; name: "String"; ofType: null };
615615
};
616616
};
617+
block: {
618+
name: "block";
619+
type: {
620+
kind: "NON_NULL";
621+
name: never;
622+
ofType: { kind: "SCALAR"; name: "Int"; ofType: null };
623+
};
624+
};
617625
created: {
618626
name: "created";
619627
type: {
@@ -864,7 +872,6 @@ export type introspection_types = {
864872
MarketRankData: {
865873
kind: "UNION";
866874
name: "MarketRankData";
867-
// biome-ignore lint/complexity/noBannedTypes: <explanation>
868875
fields: {};
869876
possibleTypes: "NftRankListData" | "TokenRankListData";
870877
};
@@ -1478,7 +1485,8 @@ export type introspection_types = {
14781485
| "CREATED"
14791486
| "UPDATED"
14801487
| "DAY"
1481-
| "DATE";
1488+
| "DATE"
1489+
| "TOKENS";
14821490
};
14831491
Project: {
14841492
kind: "OBJECT";
@@ -1942,6 +1950,14 @@ export type introspection_types = {
19421950
};
19431951
};
19441952
};
1953+
search: {
1954+
name: "search";
1955+
type: {
1956+
kind: "NON_NULL";
1957+
name: never;
1958+
ofType: { kind: "OBJECT"; name: "SearchResult"; ofType: null };
1959+
};
1960+
};
19451961
searchExplorers: {
19461962
name: "searchExplorers";
19471963
type: {
@@ -2339,6 +2355,28 @@ export type introspection_types = {
23392355
};
23402356
};
23412357
};
2358+
SearchResult: {
2359+
kind: "OBJECT";
2360+
name: "SearchResult";
2361+
fields: {
2362+
answer: {
2363+
name: "answer";
2364+
type: { kind: "SCALAR"; name: "String"; ofType: null };
2365+
};
2366+
suggestions: {
2367+
name: "suggestions";
2368+
type: {
2369+
kind: "LIST";
2370+
name: never;
2371+
ofType: {
2372+
kind: "NON_NULL";
2373+
name: never;
2374+
ofType: { kind: "OBJECT"; name: "WikiSuggestion"; ofType: null };
2375+
};
2376+
};
2377+
};
2378+
};
2379+
};
23422380
SignaturePayloadInput: {
23432381
kind: "INPUT_OBJECT";
23442382
name: "SignaturePayloadInput";
@@ -2417,7 +2455,6 @@ export type introspection_types = {
24172455
SlugResult: {
24182456
kind: "UNION";
24192457
name: "SlugResult";
2420-
// biome-ignore lint/complexity/noBannedTypes: <explanation>
24212458
fields: {};
24222459
possibleTypes: "Slug" | "Valid";
24232460
};
@@ -3193,7 +3230,6 @@ export type introspection_types = {
31933230
UserWikis: {
31943231
kind: "UNION";
31953232
name: "UserWikis";
3196-
// biome-ignore lint/complexity/noBannedTypes: <explanation>
31973233
fields: {};
31983234
possibleTypes: "UserActivity" | "WikiCount";
31993235
};
@@ -3505,6 +3541,28 @@ export type introspection_types = {
35053541
};
35063542
};
35073543
};
3544+
WikiSuggestion: {
3545+
kind: "OBJECT";
3546+
name: "WikiSuggestion";
3547+
fields: {
3548+
id: {
3549+
name: "id";
3550+
type: {
3551+
kind: "NON_NULL";
3552+
name: never;
3553+
ofType: { kind: "SCALAR"; name: "ID"; ofType: null };
3554+
};
3555+
};
3556+
title: {
3557+
name: "title";
3558+
type: {
3559+
kind: "NON_NULL";
3560+
name: never;
3561+
ofType: { kind: "SCALAR"; name: "String"; ofType: null };
3562+
};
3563+
};
3564+
};
3565+
};
35083566
WikiUrl: {
35093567
kind: "OBJECT";
35103568
name: "WikiUrl";

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getUserCreatedWikisTool } from "./tools/get-user-created-wikis.js";
44
import { getUserEditedWikisTool } from "./tools/get-user-edited-wikis.js";
55
import { getWikiActivitiesTool } from "./tools/get-user-wiki-activities.js";
66
import { getWikiTool } from "./tools/get-wiki.js";
7+
import { searchWikiTool } from "./tools/search-wiki.js";
78

89
async function main() {
910
console.log("Initializing IQ Wiki MCP Server...");
@@ -17,6 +18,7 @@ async function main() {
1718
server.addTool(getUserCreatedWikisTool);
1819
server.addTool(getUserEditedWikisTool);
1920
server.addTool(getWikiActivitiesTool);
21+
server.addTool(searchWikiTool);
2022

2123
try {
2224
await server.start({

src/lib/queries.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,15 @@ export const WIKI_QUERY = graphql(`
148148
}
149149
}
150150
`);
151+
152+
export const SEARCH_WIKIS_QUERY = graphql(`
153+
query searchWikis($query: String!) {
154+
search(query: $query) {
155+
answer
156+
suggestions {
157+
id
158+
title
159+
}
160+
}
161+
}
162+
`);

src/services/search-wiki.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import dedent from "dedent";
2+
import { client } from "../lib/graphql.js";
3+
import { SEARCH_WIKIS_QUERY } from "../lib/queries.js";
4+
5+
export class SearchWikiService {
6+
async execute(query: string) {
7+
const response = await client.request(SEARCH_WIKIS_QUERY, { query });
8+
return response.search;
9+
}
10+
11+
format(search: Awaited<ReturnType<typeof this.execute>>) {
12+
const formattedSearch = dedent`
13+
📜 Search Results
14+
- Answer: ${search.answer}
15+
- Wiki Suggestions: ${(search.suggestions ?? [])
16+
.map(
17+
(suggestion: {
18+
id: string;
19+
title: string;
20+
}) => `${suggestion.title} (${suggestion.id})`,
21+
)
22+
.join(", ")}
23+
`;
24+
25+
return formattedSearch;
26+
}
27+
}

src/tools/search-wiki.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { z } from "zod";
2+
import { SearchWikiService } from "../services/search-wiki.js";
3+
4+
const searchWikiParams = z.object({
5+
query: z.string().min(1).describe("The query to search for"),
6+
});
7+
8+
type SearchWikiParams = z.infer<typeof searchWikiParams>;
9+
10+
export const searchWikiTool = {
11+
name: "SEARCH_WIKI",
12+
description: "Search for a wiki from IQ.wiki by query",
13+
parameters: searchWikiParams,
14+
execute: async (params: SearchWikiParams) => {
15+
try {
16+
const service = new SearchWikiService();
17+
const search = await service.execute(params.query);
18+
19+
return service.format(search);
20+
} catch (error) {
21+
if (error instanceof Error) {
22+
console.log(`Error in SEARCH_WIKI tool: ${error.message}`);
23+
return `Error searching for wiki: ${error.message}`;
24+
}
25+
return "An unknown error occurred while searching for wiki data";
26+
}
27+
},
28+
} as const;

0 commit comments

Comments
 (0)