Skip to content

Commit 6738c1c

Browse files
committed
Add SMW query support to MCP server
- Add smw_query tool to mcp_server.py for executing Semantic MediaWiki ask queries - Use existing SMWClient from wikibot3rd.smw - Related to issue #5
1 parent 498e621 commit 6738c1c

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

wikibot3rd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.19.3"
1+
__version__ = "0.19.4"

wikibot3rd/mcp_server.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"fastmcp is required for MCP server. Install with: pip install py-3rdparty-mediawiki[mcp]"
1818
)
1919

20+
from wikibot3rd.smw import SMWClient
2021
from wikibot3rd.version import Version
2122
from wikibot3rd.wikiclient import WikiClient
2223
from wikibot3rd.wikiuser import WikiUser
@@ -926,6 +927,27 @@ def get_page_html(wiki_id: str, page_title: str) -> str:
926927
return get_page_html_impl(wiki_id, page_title)
927928

928929

930+
@mcp.tool()
931+
def smw_query(wiki_id: str, query: str, limit: int = 20) -> Dict[str, Any]:
932+
"""
933+
Execute a Semantic MediaWiki (SMW) ask query.
934+
935+
Args:
936+
wiki_id: The wiki identifier.
937+
query: The SMW ask query (e.g., "[[Category:MyCategory]]").
938+
limit: Maximum number of results (default 20).
939+
940+
Returns:
941+
Dict mapping page titles to their property values.
942+
Example: {"Page Name": {"Has property": "value", ...}, ...}
943+
"""
944+
client = get_wiki_client(wiki_id)
945+
site = client.get_site()
946+
smw_client = SMWClient(site)
947+
query_result = smw_client.query(query, limit=limit)
948+
return query_result
949+
950+
929951
def main():
930952
"""Run the MCP server."""
931953
mcp.run()

wikibot3rd/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Version(object):
1515
name = "py-3rdparty-mediawiki"
1616
version = wikibot3rd.__version__
1717
date = "2020-10-31"
18-
updated = "2026-03-19"
18+
updated = "2026-03-25"
1919

2020
authors = "Wolfgang Fahl, Tim Holzheim"
2121

0 commit comments

Comments
 (0)