Skip to content

Commit 9ef93b3

Browse files
committed
fix(MCP): Fix the MCP resources to work with the new file format added in [v0.11.2](#0112---2025-10-22)
1 parent 2cccf31 commit 9ef93b3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

wiki_rag/mcp_server/server.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,58 +125,58 @@ async def generate(messages: list[Message]) -> dict[str, str]:
125125
@mcp.resource("resource://get_10_pages")
126126
def get_10_pages() -> list[dict]:
127127
"""Get the first 10 parsed pages."""
128-
logger.info("Resource: Getting 10 pages")
128+
logger.info(f"Resource: Getting 10 pages from {mcp_global.res_file}")
129129
# First of all, load the json from the resource file and verify that everything is ok.
130130
if mcp_global.res_file is None:
131131
error_msg = "Error: resource file not set."
132132
raise RuntimeError(error_msg)
133-
pages = load_parsed_information(mcp_global.res_file)
134-
if not pages:
133+
information = load_parsed_information(mcp_global.res_file)
134+
if not information:
135135
error_msg = f"Error: loading and parsing the resource file {mcp_global.res_file}."
136136
raise RuntimeError(error_msg)
137137

138-
return pages[:10]
138+
return information["sites"][0]["pages"][:10]
139139

140140

141141
# Add a resource that returns the first 100 parsed pages.
142142
@mcp.resource("resource://get_100_pages")
143143
def get_100_pages() -> list[dict]:
144144
"""Get the first 100 parsed pages."""
145-
logger.info("Resource: Getting 100 pages")
145+
logger.info(f"Resource: Getting 100 pages from {mcp_global.res_file}")
146146
# First of all, load the json from the resource file and verify that everything is ok.
147147
if mcp_global.res_file is None:
148148
error_msg = "Error: resource file not set."
149149
raise RuntimeError(error_msg)
150-
pages = load_parsed_information(mcp_global.res_file)
151-
if not pages:
150+
information = load_parsed_information(mcp_global.res_file)
151+
if not information:
152152
error_msg = f"Error: loading and parsing the resource file {mcp_global.res_file}."
153153
raise RuntimeError(error_msg)
154154

155-
return pages[:100]
155+
return information["sites"][0]["pages"][:100]
156156

157157

158158
# Add a resource template that accepts start and number of pages to return.
159159
@mcp.resource("resource://get_pages/{start}/{number}")
160160
def get_pages(start: int, number: int) -> list[dict]:
161161
"""Get "number" parsed pages, starting from "start"."""
162-
logger.info(f"Resource: Getting {number} pages starting at {start}")
162+
logger.info(f"Resource: Getting {number} pages starting at {start} from {mcp_global.res_file}")
163163
# First of all, load the json from the resource file and verify that everything is ok.
164164
if mcp_global.res_file is None:
165165
error_msg = "Error: resource file not set."
166166
raise RuntimeError(error_msg)
167-
pages = load_parsed_information(mcp_global.res_file)
168-
if not pages:
167+
information = load_parsed_information(mcp_global.res_file)
168+
if not information:
169169
error_msg = f"Error: loading and parsing the resource file {mcp_global.res_file}."
170170
raise RuntimeError(error_msg)
171171
# Check that the start and number are valid.
172-
if (start - 1 + number) > len(pages):
172+
if (start - 1 + number) > len(information["sites"][0]["pages"]):
173173
error_msg = f"Error: start ({start}) and number ({number}) are out of range."
174174
raise ValueError(error_msg)
175175
if start < 1:
176176
error_msg = f"Error: start ({start}) must be greater than 0."
177177
raise ValueError(error_msg)
178178

179-
return pages[start - 1:start - 1 + number]
179+
return information["sites"][0]["pages"][start - 1:start - 1 + number]
180180

181181

182182
@mcp.prompt()

0 commit comments

Comments
 (0)