Skip to content

Commit f4b0530

Browse files
committed
Clarify base_url docs and add server instructions
Update: clarify the Annotated base_url parameter docstrings across mcp modules (collection, dataset, dataverse, file, search) to state that the MCP server's connected dataverse is used by default. Add DataverseMCP.base_url and base_url_instructions properties and include the base_url_instructions text in multiple tool descriptions so tools explicitly inform users which dataverse the MCP is connected to and how to override it. Also tighten dependency version bounds in pyproject.toml for several optional mcp-related packages.
1 parent 5bb4ef1 commit f4b0530

7 files changed

Lines changed: 59 additions & 33 deletions

File tree

pyDataverse/mcp/collection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def get_collection_metadata(
1717
],
1818
base_url: Annotated[
1919
Optional[str],
20-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
21-
],
20+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
21+
] = None,
2222
ctx: Context = CurrentContext(),
2323
) -> str:
2424
"""
@@ -39,8 +39,8 @@ def list_content(
3939
],
4040
base_url: Annotated[
4141
Optional[str],
42-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
43-
],
42+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
43+
] = None,
4444
ctx: Context = CurrentContext(),
4545
) -> str:
4646
"""
@@ -80,7 +80,7 @@ def get_graph_summary(
8080
depth: int = 3,
8181
base_url: Annotated[
8282
Optional[str],
83-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
83+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
8484
] = None,
8585
ctx: Context = CurrentContext(),
8686
) -> str:
@@ -130,7 +130,7 @@ def query_sparql(
130130
] = 3,
131131
base_url: Annotated[
132132
Optional[str],
133-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
133+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
134134
] = None,
135135
ctx: Context = CurrentContext(),
136136
) -> str:

pyDataverse/mcp/dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def get_dataset(
4343
],
4444
base_url: Annotated[
4545
Optional[str],
46-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
47-
],
46+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
47+
] = None,
4848
ctx: Context = CurrentContext(),
4949
):
5050
"""
@@ -119,8 +119,8 @@ def list_files(
119119
],
120120
base_url: Annotated[
121121
Optional[str],
122-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
123-
],
122+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
123+
] = None,
124124
ctx: Context = CurrentContext(),
125125
):
126126
"""

pyDataverse/mcp/dataverse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def get_metrics(
1111
base_url: Annotated[
1212
Optional[str],
13-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
13+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
1414
] = None,
1515
ctx: Context = CurrentContext(),
1616
):

pyDataverse/mcp/file.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def read_file(
9090
],
9191
base_url: Annotated[
9292
Optional[str],
93-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
94-
],
93+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
94+
] = None,
9595
ctx: Context = CurrentContext(),
9696
) -> Union[ImageContent, List[TextContent], EmbeddedResource, TextContent]:
9797
"""
@@ -209,7 +209,7 @@ def read_tabular(
209209
] = None,
210210
base_url: Annotated[
211211
Optional[str],
212-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
212+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
213213
] = None,
214214
ctx: Context = CurrentContext(),
215215
) -> str:
@@ -280,7 +280,7 @@ def tabular_schema(
280280
],
281281
base_url: Annotated[
282282
Optional[str],
283-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
283+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
284284
] = None,
285285
ctx: Context = CurrentContext(),
286286
) -> str:

pyDataverse/mcp/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def search(
117117
per_page: Annotated[int, "Maximum number of results to return per page"] = 10,
118118
base_url: Annotated[
119119
Optional[str],
120-
"The base URL of the dataverse to use. If not specified, the function will use the dataverse from the context.",
120+
"The base URL of the dataverse to use. If not specified, the function will use the dataverse this MCP server is connected to by default.",
121121
] = None,
122122
ctx: Context = CurrentContext(),
123123
):

pyDataverse/mcp/server.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ def __init__(
8585

8686
self.config = config or MCPConfiguration()
8787

88+
@property
89+
def base_url(self) -> str:
90+
"""
91+
Get the base URL of the dataverse.
92+
"""
93+
return self.dataverse.base_url
94+
95+
@property
96+
def base_url_instructions(self) -> str:
97+
"""
98+
Get the base URL instructions for the dataverse.
99+
"""
100+
return f"This MCP server is connected to the dataverse at {self.base_url}. Provide the `base_url` parameter if you want to use a different dataverse."
101+
88102
def to_mcp(self, mcp: FastMCP):
89103
"""
90104
Configure the provided FastMCP instance with Dataverse tools and middleware.
@@ -116,7 +130,7 @@ def _add_dataverse_tools(self, mcp: FastMCP):
116130
mcp.tool(
117131
get_metrics,
118132
name="Dataverse_Metrics",
119-
description="Get metrics from the dataverse in total and for the past 7 days. This tool returns the metrics of the dataverse in a TOON format.",
133+
description=f"Get metrics from the dataverse in total and for the past 7 days. This tool returns the metrics of the dataverse in a TOON format. {self.base_url_instructions}",
120134
)
121135

122136
def _add_dataset_tools(self, mcp: FastMCP):
@@ -142,14 +156,16 @@ def _add_dataset_tools(self, mcp: FastMCP):
142156
The available metadata blocks are: {", ".join(available_metadatablocks)}.
143157
If you do not specify the metadata blocks, the function will return all metadata blocks.
144158
To save tokens and compute resources, you should first request the dataset without the `full` flag to get the available metadata blocks and then request the dataset with the `full` flag and the metadata blocks you want to see.
159+
160+
{self.base_url_instructions}
145161
""".strip(),
146162
)
147163

148164
mcp.tool(
149165
list_files,
150166
name="List_Files_in_Dataset",
151167
enabled="read" in self.config.dataset,
152-
description="List the files in a dataset. This tool returns the files in a TOON format.",
168+
description=f"List the files in a dataset. This tool returns the files in a TOON format. {self.base_url_instructions}",
153169
)
154170

155171
def _add_file_tools(self, mcp: FastMCP):
@@ -168,28 +184,32 @@ def _add_file_tools(self, mcp: FastMCP):
168184
read_tabular,
169185
name="Read_Tabular_File",
170186
enabled="read" in self.config.file,
171-
description="""
187+
description=f"""
172188
Read a tabular file from a dataset. This tool returns the file in a TOON format.
173189
When `summarize` is True, the function will return the description of the file using the `describe` method of the pandas DataFrame.
174190
When `n_rows` is specified, the function will return the first `n_rows` rows of the file.
175191
When `n_rows` is not specified, the function will return the entire file. Please note that this is capped to 1000 rows.
192+
193+
{self.base_url_instructions}
176194
""".strip(),
177195
)
178196

179197
mcp.tool(
180198
read_file,
181199
name="Read_File_Content",
182200
enabled="read" in self.config.file,
183-
description="""
201+
description=f"""
184202
Read then content of a file from a dataset. This tool returns the raw content of the file.
203+
204+
{self.base_url_instructions}
185205
""".strip(),
186206
)
187207

188208
mcp.tool(
189209
tabular_schema,
190210
name="Get_Tabular_File_Schema",
191211
enabled="read" in self.config.file,
192-
description="Get the schema of a tabular file. This tool returns the schema of the file in a TOON format.",
212+
description=f"Get the schema of a tabular file. This tool returns the schema of the file in a TOON format. {self.base_url_instructions}",
193213
)
194214

195215
def _add_collection_tools(self, mcp: FastMCP):
@@ -206,42 +226,48 @@ def _add_collection_tools(self, mcp: FastMCP):
206226
get_collection_metadata,
207227
name="Get_Collection_Metadata",
208228
enabled="read" in self.config.collection,
209-
description="Get the metadata of a collection. This tool returns the metadata of the collection in a TOON format.",
229+
description=f"Get the metadata of a collection. This tool returns the metadata of the collection in a TOON format. {self.base_url_instructions}",
210230
)
211231

212232
mcp.tool(
213233
list_content,
214234
name="List_Content_of_Collection",
215235
enabled="read" in self.config.collection,
216-
description="""
236+
description=f"""
217237
List the content of a collection. This tool returns the content in a TOON format.
218238
You can filter the content by type. The available types are: dataset, collection.
239+
240+
{self.base_url_instructions}
219241
""".strip(),
220242
)
221243

222244
mcp.tool(
223245
get_graph_summary,
224246
name="Knowledge_Graph_Summary",
225247
enabled="graph" in self.config.collection,
226-
description="""
248+
description=f"""
227249
Get the summary of the RDF graph of a collection. This tool returns all classes and predicates
228250
found in the collection's knowledge graph, including their full URIs and short names.
229251
Useful for exploring the semantic structure of a collection before writing SPARQL queries.
230252
The graph can be generated in different formats: "croissant" or "OAI_ORE".
231253
Returns the summary in a TOON format.
254+
255+
{self.base_url_instructions}
232256
""".strip(),
233257
)
234258

235259
mcp.tool(
236260
query_sparql,
237261
name="Query_Knowledge_Graph",
238262
enabled="graph" in self.config.collection,
239-
description="""
263+
description=f"""
240264
Execute a SPARQL query against a collection's RDF graph. This tool allows you to query the
241265
semantic metadata of a collection using SPARQL syntax. The graph can be generated in different
242266
formats: "croissant" or "OAI_ORE". Query results are returned as a list of dictionaries where
243267
each dictionary represents a result row with variable names as keys. Use get_graph_summary first
244268
to explore available classes and predicates before writing queries. Returns results in a TOON format.
269+
270+
{self.base_url_instructions}
245271
""".strip(),
246272
)
247273

pyproject.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies = [
2121
"asyncer>=0.0.10,<0.0.11",
2222
"bigtree>=1.0.0,<2.0.0",
2323
"rdflib>=7.5.0,<8.0.0",
24-
"sniffio>=1.3.1",
24+
"sniffio>=1.3.1<2.0.0",
2525
]
2626

2727
[project.optional-dependencies]
@@ -35,13 +35,13 @@ tests = [
3535
"ruff>=0.4.4,<0.5.0",
3636
]
3737
mcp = [
38-
"fastmcp>=2.14.5",
39-
"mcp>=1.26.0",
40-
"nbconvert>=7.17.0",
41-
"nbformat>=5.10.4",
42-
"pillow>=12.1.1",
43-
"pymupdf>=1.27.1",
44-
"toon-format==0.9.0b1",
38+
"fastmcp>=2.14.5<3.0.0",
39+
"mcp>=1.26.0<2.0.0",
40+
"nbconvert>=7.17.0<8.0.0",
41+
"nbformat>=5.10.4<6.0.0",
42+
"pillow>=12.1.1<13.0.0",
43+
"pymupdf>=1.27.1<2.0.0",
44+
"toon-format==0.9.0b1<0.10.0",
4545
]
4646

4747
[project.urls]

0 commit comments

Comments
 (0)