@dataville/dataville-mcp 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const DEFAULT_BASE_URL = "https://api.dataville.com";
2
2
  // Keep in sync with package.json version (enforced by a test).
3
- export const VERSION = "0.1.1";
3
+ export const VERSION = "0.1.3";
4
4
  const USER_AGENT = `dataville-mcp/${VERSION}`;
5
5
  export class DatavilleApiError extends Error {
6
6
  status;
@@ -10,6 +10,21 @@ export class DatavilleApiError extends Error {
10
10
  this.name = "DatavilleApiError";
11
11
  }
12
12
  }
13
+ /**
14
+ * Raised when the API accepted the request but did not recognise our API key.
15
+ *
16
+ * Dataville's auth middleware never rejects outright — an unrecognised key
17
+ * falls through to anonymous access, which still returns data but under the
18
+ * much lower anonymous rate limit and without attributing usage to the
19
+ * account. Left unchecked that failure is invisible inside an MCP client, so
20
+ * we surface it explicitly instead of returning results that look fine.
21
+ */
22
+ export class DatavilleAuthError extends Error {
23
+ constructor(message) {
24
+ super(message);
25
+ this.name = "DatavilleAuthError";
26
+ }
27
+ }
13
28
  function getConfig() {
14
29
  const apiKey = process.env.DATAVILLE_API_KEY;
15
30
  if (!apiKey) {
@@ -34,9 +49,27 @@ export async function searchDataSource(source, keywords, params) {
34
49
  });
35
50
  const body = await response.json().catch(() => undefined);
36
51
  if (!response.ok) {
37
- const message = (body && typeof body === "object" && "error" in body && String(body.error)) ||
38
- `Dataville API request failed with status ${response.status}`;
52
+ // Errors come back as { status: "error", data: { error: "..." } }. Those
53
+ // messages are useful to the model — "no results for X", or the full list
54
+ // of valid sources — so prefer them over a bare status code.
55
+ const apiMessage = body && typeof body === "object"
56
+ ? body.data?.error ??
57
+ body.error
58
+ : undefined;
59
+ const message = typeof apiMessage === "string" && apiMessage.length > 0
60
+ ? apiMessage
61
+ : `Dataville API request failed with status ${response.status}`;
39
62
  throw new DatavilleApiError(response.status, message);
40
63
  }
64
+ // We always send an API key, so an "anonymous" account state means the key
65
+ // was not accepted. Fail loudly rather than silently serving anonymous-tier
66
+ // results that are neither attributed nor billed to the user's account.
67
+ if (body &&
68
+ typeof body === "object" &&
69
+ body.account_state === "anonymous") {
70
+ throw new DatavilleAuthError("Your DATAVILLE_API_KEY was not recognised, so this request fell back to anonymous access " +
71
+ "(much lower rate limits, and usage is not attributed to your account). " +
72
+ "Check the key in your MCP client config, or generate a new one at https://app.dataville.com/api-keys.");
73
+ }
41
74
  return body;
42
75
  }
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
4
  import { z } from "zod";
5
- import { searchDataSource, DatavilleApiError, VERSION } from "./client.js";
5
+ import { searchDataSource, VERSION } from "./client.js";
6
6
  import { DATAVILLE_SOURCES } from "./sources.js";
7
7
  const server = new McpServer({
8
8
  name: "dataville-mcp-server",
@@ -32,7 +32,7 @@ server.registerTool("search_dataville", {
32
32
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
33
33
  }
34
34
  catch (error) {
35
- const message = error instanceof DatavilleApiError ? error.message : String(error);
35
+ const message = error instanceof Error ? error.message : String(error);
36
36
  return { content: [{ type: "text", text: message }], isError: true };
37
37
  }
38
38
  });
package/dist/sources.js CHANGED
@@ -1,14 +1,17 @@
1
1
  // Hand-maintained list of data sources supported by the Dataville API.
2
- // Update when Dataville adds or removes a supported source.
2
+ // The `name` values must match the source names the API accepts — a mismatch
3
+ // makes the source unreachable. To check against the live API, request an
4
+ // unknown source (e.g. /nosuchsource/foo); the error lists every valid name.
3
5
  export const DATAVILLE_SOURCES = [
4
6
  { name: "wikipedia", description: "Wikipedia articles" },
5
7
  { name: "arxiv", description: "arXiv preprints" },
6
8
  { name: "gutenberg", description: "Project Gutenberg public-domain books" },
7
9
  { name: "census", description: "US Census Bureau data" },
8
10
  { name: "fooddata", description: "USDA FoodData Central" },
9
- { name: "pwc", description: "Papers with Code — ML papers, code, and benchmarks" },
11
+ { name: "paperswithcode", description: "Papers with Code — ML papers, code, and benchmarks" },
10
12
  { name: "edgar", description: "SEC EDGAR filings" },
11
13
  { name: "openalex", description: "OpenAlex scholarly works" },
12
14
  { name: "pypi", description: "PyPI package metadata" },
13
15
  { name: "stackexchange", description: "Stack Exchange Q&A" },
16
+ { name: "news", description: "News front-page headlines and summaries" },
14
17
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataville/dataville-mcp",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "MCP server exposing Dataville's data source API as tools for MCP clients",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -22,7 +22,8 @@
22
22
  "prepublishOnly": "npm run build",
23
23
  "dev": "tsx watch src/index.ts",
24
24
  "start": "node dist/index.js",
25
- "test": "tsx --test src/__tests__/*.test.ts"
25
+ "test": "tsx --test src/__tests__/*.test.ts",
26
+ "test:integration": "tsx --test src/__tests__/*.itest.ts"
26
27
  },
27
28
  "dependencies": {
28
29
  "@modelcontextprotocol/sdk": "^1.12.0",