@pipeworx/mcp-barcelona-events 0.1.0
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/LICENSE +21 -0
- package/README.md +55 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +183 -0
- package/tsconfig.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pipeworx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# mcp-barcelona-events
|
|
2
|
+
|
|
3
|
+
Barcelona Events MCP.
|
|
4
|
+
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 908+ live data sources.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"mcpServers": {
|
|
19
|
+
"barcelona-events": {
|
|
20
|
+
"url": "https://gateway.pipeworx.io/barcelona-events/mcp"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or connect to the full Pipeworx gateway for access to all 908+ data sources:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"pipeworx": {
|
|
32
|
+
"url": "https://gateway.pipeworx.io/mcp"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Using with ask_pipeworx
|
|
39
|
+
|
|
40
|
+
Instead of calling tools directly, you can ask questions in plain English:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
ask_pipeworx({ question: "your question about Barcelona Events data" })
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The gateway picks the right tool and fills the arguments automatically.
|
|
47
|
+
|
|
48
|
+
## More
|
|
49
|
+
|
|
50
|
+
- [All tools and guides](https://github.com/pipeworx-io/examples)
|
|
51
|
+
- [pipeworx.io](https://pipeworx.io)
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-barcelona-events",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Barcelona Events MCP.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "barcelona-events"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-barcelona-events"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"typecheck": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.pipeworx-io/barcelona-events",
|
|
4
|
+
"title": "Barcelona Events",
|
|
5
|
+
"description": "Barcelona Events MCP.",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/barcelona-events",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-barcelona-events",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/barcelona-events/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
interface McpToolDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: 'object';
|
|
6
|
+
properties: Record<string, unknown>;
|
|
7
|
+
required?: string[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface McpToolExport {
|
|
12
|
+
tools: McpToolDefinition[];
|
|
13
|
+
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
14
|
+
meter?: { credits: number };
|
|
15
|
+
cost?: Record<string, unknown>;
|
|
16
|
+
provider?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Barcelona Events MCP.
|
|
21
|
+
*
|
|
22
|
+
* Cultural events & activities in Barcelona, Spain from the city's open-data
|
|
23
|
+
* portal (opendata-ajuntament.barcelona.cat, "agenda-cultural" CKAN datastore).
|
|
24
|
+
* Keyless, ~2,400 distinct upcoming events. The source is denormalised (several
|
|
25
|
+
* rows per event), so we de-duplicate by register_id in SQL. Filter by keyword,
|
|
26
|
+
* district and date window. Content is in Catalan/Spanish.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const SQL_URL = 'https://opendata-ajuntament.barcelona.cat/data/api/3/action/datastore_search_sql';
|
|
31
|
+
const RESOURCE_ID = '3abb2414-1ee0-446e-9c25-380e938adb73';
|
|
32
|
+
const UA = 'pipeworx-mcp-barcelona-events/1.0 (+https://pipeworx.io)';
|
|
33
|
+
const MAX_LIMIT = 50;
|
|
34
|
+
const COLS = [
|
|
35
|
+
'register_id', 'name', 'institution_name', 'start_date', 'end_date', 'timetable',
|
|
36
|
+
'addresses_road_name', 'addresses_start_street_number', 'addresses_neighborhood_name',
|
|
37
|
+
'addresses_district_name', 'addresses_zip_code', 'geo_epgs_4326_lat', 'geo_epgs_4326_lon',
|
|
38
|
+
'values_category', 'values_description',
|
|
39
|
+
].join(',');
|
|
40
|
+
|
|
41
|
+
const tools: McpToolExport['tools'] = [
|
|
42
|
+
{
|
|
43
|
+
name: 'events',
|
|
44
|
+
description:
|
|
45
|
+
'Find upcoming cultural events & activities in Barcelona, Spain. Filter by keyword, district (e.g. "Eixample", "Ciutat Vella", "Gràcia") and date window. Returns events with venue, district, coordinates and dates. Content is in Catalan/Spanish.',
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
query: { type: 'string', description: 'Keyword over title and description, e.g. "música", "exposició", "infantil".' },
|
|
50
|
+
district: { type: 'string', description: 'Filter by district, e.g. "Eixample", "Ciutat Vella", "Gràcia", "Sant Martí".' },
|
|
51
|
+
from: { type: 'string', description: 'Include events ending on/after this date YYYY-MM-DD (default: today).' },
|
|
52
|
+
to: { type: 'string', description: 'Include events starting on/before this date YYYY-MM-DD.' },
|
|
53
|
+
limit: { type: 'number', description: `Max events (1-${MAX_LIMIT}, default 20).` },
|
|
54
|
+
offset: { type: 'number', description: 'Pagination offset (default 0).' },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
61
|
+
if (name !== 'events') throw new Error(`Unknown tool: ${name}`);
|
|
62
|
+
|
|
63
|
+
const from = dateArg(args.from) || todayISO();
|
|
64
|
+
const to = dateArg(args.to);
|
|
65
|
+
const where: string[] = [`end_date >= '${from}'`];
|
|
66
|
+
if (to) where.push(`start_date <= '${to}T23:59:59'`);
|
|
67
|
+
if (typeof args.district === 'string' && args.district.trim()) where.push(`addresses_district_name ILIKE '%${sql(args.district)}%'`);
|
|
68
|
+
if (typeof args.query === 'string' && args.query.trim()) {
|
|
69
|
+
const q = sql(args.query);
|
|
70
|
+
where.push(`(name ILIKE '%${q}%' OR values_description ILIKE '%${q}%')`);
|
|
71
|
+
}
|
|
72
|
+
const clause = where.join(' AND ');
|
|
73
|
+
const limit = clamp(numArg(args.limit, 20), 1, MAX_LIMIT);
|
|
74
|
+
const offset = Math.max(0, numArg(args.offset, 0));
|
|
75
|
+
|
|
76
|
+
const total = await count(clause);
|
|
77
|
+
// De-dup the denormalised rows to one per event, then order by date.
|
|
78
|
+
const rows = (await runSql(
|
|
79
|
+
`SELECT * FROM (SELECT DISTINCT ON (register_id) ${COLS} FROM "${RESOURCE_ID}" WHERE ${clause} ORDER BY register_id, _id) sub ORDER BY start_date ASC LIMIT ${limit} OFFSET ${offset}`,
|
|
80
|
+
)) as BcnRow[];
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
city: 'Barcelona',
|
|
84
|
+
country: 'Spain',
|
|
85
|
+
source: 'opendata-ajuntament.barcelona.cat',
|
|
86
|
+
date_from: from,
|
|
87
|
+
date_to: to || null,
|
|
88
|
+
total_matching: total,
|
|
89
|
+
count: rows.length,
|
|
90
|
+
events: rows.map(normalize),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function count(clause: string): Promise<number> {
|
|
95
|
+
try {
|
|
96
|
+
const r = (await runSql(`SELECT COUNT(DISTINCT register_id) AS n FROM "${RESOURCE_ID}" WHERE ${clause}`)) as { n?: string | number }[];
|
|
97
|
+
return Number(r[0]?.n ?? 0);
|
|
98
|
+
} catch {
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function runSql(sqlText: string): Promise<unknown[]> {
|
|
104
|
+
const res = await fetch(`${SQL_URL}?sql=${encodeURIComponent(sqlText)}`, { headers: { Accept: 'application/json', 'User-Agent': UA } });
|
|
105
|
+
const body = (await res.json().catch(() => ({}))) as { success?: boolean; result?: { records?: unknown[] }; error?: { message?: string } };
|
|
106
|
+
if (!res.ok || body.success === false) throw new Error(`Barcelona: ${body.error?.message || `HTTP ${res.status}`}`);
|
|
107
|
+
return body.result?.records ?? [];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface BcnRow {
|
|
111
|
+
register_id?: string;
|
|
112
|
+
name?: string;
|
|
113
|
+
institution_name?: string;
|
|
114
|
+
start_date?: string;
|
|
115
|
+
end_date?: string;
|
|
116
|
+
timetable?: string;
|
|
117
|
+
addresses_road_name?: string;
|
|
118
|
+
addresses_start_street_number?: string;
|
|
119
|
+
addresses_neighborhood_name?: string;
|
|
120
|
+
addresses_district_name?: string;
|
|
121
|
+
addresses_zip_code?: string;
|
|
122
|
+
geo_epgs_4326_lat?: string | number;
|
|
123
|
+
geo_epgs_4326_lon?: string | number;
|
|
124
|
+
values_category?: string;
|
|
125
|
+
values_description?: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function normalize(e: BcnRow): Record<string, unknown> {
|
|
129
|
+
const street = [e.addresses_road_name, e.addresses_start_street_number].filter((p) => p && String(p).trim()).join(' ');
|
|
130
|
+
return {
|
|
131
|
+
id: e.register_id ? e.register_id.replace(/\D/g, "") || undefined : undefined,
|
|
132
|
+
title: e.name,
|
|
133
|
+
category: e.values_category || undefined,
|
|
134
|
+
date_start: fixDate(e.start_date),
|
|
135
|
+
date_end: fixDate(e.end_date) && fixDate(e.end_date) !== fixDate(e.start_date) ? fixDate(e.end_date) : undefined,
|
|
136
|
+
timetable: e.timetable?.trim() || undefined,
|
|
137
|
+
summary: e.values_description ? e.values_description.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 600) : undefined,
|
|
138
|
+
venue: {
|
|
139
|
+
name: e.institution_name || undefined,
|
|
140
|
+
address: [street, e.addresses_zip_code, 'Barcelona'].filter((p) => p && String(p).trim()).join(', ') || undefined,
|
|
141
|
+
neighborhood: e.addresses_neighborhood_name || undefined,
|
|
142
|
+
district: e.addresses_district_name || undefined,
|
|
143
|
+
latitude: numOrUndef(e.geo_epgs_4326_lat),
|
|
144
|
+
longitude: numOrUndef(e.geo_epgs_4326_lon),
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Some records have a typoed year like "0026-07-01" — coerce a sub-100 year to 20xx. */
|
|
150
|
+
function fixDate(s?: string): string {
|
|
151
|
+
if (typeof s !== 'string') return '';
|
|
152
|
+
const m = s.match(/^(\d{4})-(\d{2})-(\d{2})/);
|
|
153
|
+
if (!m) return '';
|
|
154
|
+
let y = Number(m[1]);
|
|
155
|
+
if (y < 100) y += 2000;
|
|
156
|
+
return `${y}-${m[2]}-${m[3]}`;
|
|
157
|
+
}
|
|
158
|
+
/** Escape single quotes for the read-only datastore SQL (SELECT-only endpoint). */
|
|
159
|
+
function sql(v: string): string {
|
|
160
|
+
return v.trim().replace(/'/g, "''").replace(/[;\\]/g, '').slice(0, 80);
|
|
161
|
+
}
|
|
162
|
+
function numOrUndef(v: unknown): number | undefined {
|
|
163
|
+
const n = typeof v === 'number' ? v : typeof v === 'string' ? Number(v) : NaN;
|
|
164
|
+
return Number.isFinite(n) && n !== 0 ? n : undefined;
|
|
165
|
+
}
|
|
166
|
+
function dateArg(v: unknown): string {
|
|
167
|
+
if (typeof v !== 'string') return '';
|
|
168
|
+
const m = v.trim().match(/^(\d{4})-(\d{2})-(\d{2})/);
|
|
169
|
+
return m ? `${m[1]}-${m[2]}-${m[3]}` : '';
|
|
170
|
+
}
|
|
171
|
+
function todayISO(): string {
|
|
172
|
+
const d = new Date(Date.now() + 2 * 3600 * 1000); // approx Barcelona (CEST)
|
|
173
|
+
return `${d.getUTCFullYear()}-${String(d.getUTCMonth() + 1).padStart(2, '0')}-${String(d.getUTCDate()).padStart(2, '0')}`;
|
|
174
|
+
}
|
|
175
|
+
function numArg(v: unknown, dflt: number): number {
|
|
176
|
+
const n = typeof v === 'number' ? v : typeof v === 'string' ? Number(v) : NaN;
|
|
177
|
+
return Number.isFinite(n) ? n : dflt;
|
|
178
|
+
}
|
|
179
|
+
function clamp(n: number, lo: number, hi: number): number {
|
|
180
|
+
return Math.max(lo, Math.min(hi, Math.trunc(n)));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|