@cyanheads/openlibrary-mcp-server 0.1.1
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/CLAUDE.md +391 -0
- package/Dockerfile +98 -0
- package/LICENSE +201 -0
- package/README.md +316 -0
- package/changelog/0.1.x/0.1.0.md +22 -0
- package/changelog/0.1.x/0.1.1.md +25 -0
- package/changelog/template.md +119 -0
- package/dist/config/server-config.d.ts +11 -0
- package/dist/config/server-config.d.ts.map +1 -0
- package/dist/config/server-config.js +20 -0
- package/dist/config/server-config.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server/resources/definitions/openlibrary-author.resource.d.ts +25 -0
- package/dist/mcp-server/resources/definitions/openlibrary-author.resource.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/openlibrary-author.resource.js +48 -0
- package/dist/mcp-server/resources/definitions/openlibrary-author.resource.js.map +1 -0
- package/dist/mcp-server/resources/definitions/openlibrary-work.resource.d.ts +21 -0
- package/dist/mcp-server/resources/definitions/openlibrary-work.resource.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/openlibrary-work.resource.js +42 -0
- package/dist/mcp-server/resources/definitions/openlibrary-work.resource.js.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-author-works.tool.d.ts +26 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-author-works.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-author-works.tool.js +68 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-author-works.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-author.tool.d.ts +31 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-author.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-author.tool.js +86 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-author.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-cover-url.tool.d.ts +26 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-cover-url.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-cover-url.tool.js +56 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-cover-url.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-edition.tool.d.ts +45 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-edition.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-edition.tool.js +132 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-edition.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-editions.tool.d.ts +32 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-editions.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-editions.tool.js +106 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-editions.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-subject.tool.d.ts +29 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-subject.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-subject.tool.js +82 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-subject.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-work.tool.d.ts +27 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-work.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-work.tool.js +90 -0
- package/dist/mcp-server/tools/definitions/openlibrary-get-work.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-search-authors.tool.d.ts +31 -0
- package/dist/mcp-server/tools/definitions/openlibrary-search-authors.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-search-authors.tool.js +105 -0
- package/dist/mcp-server/tools/definitions/openlibrary-search-authors.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-search-books.tool.d.ts +65 -0
- package/dist/mcp-server/tools/definitions/openlibrary-search-books.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/openlibrary-search-books.tool.js +217 -0
- package/dist/mcp-server/tools/definitions/openlibrary-search-books.tool.js.map +1 -0
- package/dist/services/open-library/open-library-service.d.ts +57 -0
- package/dist/services/open-library/open-library-service.d.ts.map +1 -0
- package/dist/services/open-library/open-library-service.js +347 -0
- package/dist/services/open-library/open-library-service.js.map +1 -0
- package/dist/services/open-library/types.d.ts +129 -0
- package/dist/services/open-library/types.d.ts.map +1 -0
- package/dist/services/open-library/types.js +6 -0
- package/dist/services/open-library/types.js.map +1 -0
- package/package.json +79 -0
- package/server.json +99 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Fetch a work by Open Library Work ID.
|
|
3
|
+
* @module mcp-server/tools/definitions/openlibrary-get-work.tool
|
|
4
|
+
*/
|
|
5
|
+
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
import { getOpenLibraryService } from '../../../services/open-library/open-library-service.js';
|
|
8
|
+
export const openlibraryGetWork = tool('openlibrary_get_work', {
|
|
9
|
+
title: 'Get Work',
|
|
10
|
+
description: 'Fetch a work by Open Library Work ID (OL…W). Returns title, description, subjects, cover IDs, and linked author IDs for follow-up lookups. Works represent the abstract book concept independent of any specific edition. Note: author names are not included — use openlibrary_get_author or openlibrary_search_books for names.',
|
|
11
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
|
|
12
|
+
input: z.object({
|
|
13
|
+
work_id: z
|
|
14
|
+
.string()
|
|
15
|
+
.describe('Open Library Work ID. Format: OL…W (e.g., "OL45804W"). A leading "/works/" prefix is stripped if provided.'),
|
|
16
|
+
}),
|
|
17
|
+
output: z.object({
|
|
18
|
+
work_id: z.string().describe('Canonical Open Library Work ID (OL…W).'),
|
|
19
|
+
title: z.string().describe('Work title.'),
|
|
20
|
+
description: z
|
|
21
|
+
.string()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Work description or blurb. Absent when not provided.'),
|
|
24
|
+
subjects: z.array(z.string()).describe('Subject tags for this work.'),
|
|
25
|
+
subject_places: z.array(z.string()).describe('Geographic subjects.'),
|
|
26
|
+
subject_times: z.array(z.string()).describe('Time period subjects.'),
|
|
27
|
+
subject_people: z.array(z.string()).describe('People subjects.'),
|
|
28
|
+
cover_ids: z
|
|
29
|
+
.array(z.number())
|
|
30
|
+
.describe('Numeric cover IDs. Pass to openlibrary_get_cover_url with id_type "id".'),
|
|
31
|
+
author_ids: z
|
|
32
|
+
.array(z.string())
|
|
33
|
+
.describe('Open Library Author IDs (OL…A). Use openlibrary_get_author for names and bio.'),
|
|
34
|
+
created: z
|
|
35
|
+
.string()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe('ISO 8601 creation timestamp. Absent when not available.'),
|
|
38
|
+
last_modified: z
|
|
39
|
+
.string()
|
|
40
|
+
.optional()
|
|
41
|
+
.describe('ISO 8601 last-modified timestamp. Absent when not available.'),
|
|
42
|
+
}),
|
|
43
|
+
errors: [
|
|
44
|
+
{
|
|
45
|
+
reason: 'not_found',
|
|
46
|
+
code: JsonRpcErrorCode.NotFound,
|
|
47
|
+
when: 'Work ID does not exist on Open Library.',
|
|
48
|
+
recovery: 'Verify the OLID format (e.g., "OL45804W") or use openlibrary_search_books to find the correct ID.',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
handler(input, ctx) {
|
|
52
|
+
ctx.log.info('Fetching work', { work_id: input.work_id });
|
|
53
|
+
const svc = getOpenLibraryService();
|
|
54
|
+
return svc.getWork(input.work_id, ctx);
|
|
55
|
+
},
|
|
56
|
+
format: (result) => {
|
|
57
|
+
const lines = [];
|
|
58
|
+
lines.push(`## ${result.title}`);
|
|
59
|
+
lines.push(`**Work ID:** ${result.work_id}`);
|
|
60
|
+
if (result.description) {
|
|
61
|
+
lines.push('');
|
|
62
|
+
lines.push(result.description);
|
|
63
|
+
}
|
|
64
|
+
if (result.author_ids.length) {
|
|
65
|
+
lines.push('');
|
|
66
|
+
lines.push(`**Author IDs:** ${result.author_ids.join(', ')}`);
|
|
67
|
+
}
|
|
68
|
+
if (result.cover_ids.length) {
|
|
69
|
+
lines.push(`**Cover IDs:** ${result.cover_ids.join(', ')}`);
|
|
70
|
+
}
|
|
71
|
+
if (result.subjects.length) {
|
|
72
|
+
lines.push(`**Subjects:** ${result.subjects.slice(0, 10).join(', ')}`);
|
|
73
|
+
}
|
|
74
|
+
if (result.subject_places.length) {
|
|
75
|
+
lines.push(`**Places:** ${result.subject_places.join(', ')}`);
|
|
76
|
+
}
|
|
77
|
+
if (result.subject_times.length) {
|
|
78
|
+
lines.push(`**Time periods:** ${result.subject_times.join(', ')}`);
|
|
79
|
+
}
|
|
80
|
+
if (result.subject_people.length) {
|
|
81
|
+
lines.push(`**People:** ${result.subject_people.join(', ')}`);
|
|
82
|
+
}
|
|
83
|
+
if (result.created)
|
|
84
|
+
lines.push(`**Created:** ${result.created}`);
|
|
85
|
+
if (result.last_modified)
|
|
86
|
+
lines.push(`**Last modified:** ${result.last_modified}`);
|
|
87
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=openlibrary-get-work.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openlibrary-get-work.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/openlibrary-get-work.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAExF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ACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Search Open Library authors by name.
|
|
3
|
+
* @module mcp-server/tools/definitions/openlibrary-search-authors.tool
|
|
4
|
+
*/
|
|
5
|
+
import { z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
export declare const openlibrarySearchAuthors: import("@cyanheads/mcp-ts-core").ToolDefinition<z.ZodObject<{
|
|
8
|
+
query: z.ZodString;
|
|
9
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
10
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
11
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
12
|
+
total: z.ZodNumber;
|
|
13
|
+
authors: z.ZodArray<z.ZodObject<{
|
|
14
|
+
author_id: z.ZodString;
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
alternate_names: z.ZodArray<z.ZodString>;
|
|
17
|
+
birth_date: z.ZodOptional<z.ZodString>;
|
|
18
|
+
death_date: z.ZodOptional<z.ZodString>;
|
|
19
|
+
top_work: z.ZodOptional<z.ZodString>;
|
|
20
|
+
work_count: z.ZodNumber;
|
|
21
|
+
top_subjects: z.ZodArray<z.ZodString>;
|
|
22
|
+
ratings_average: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
}, z.core.$strip>>;
|
|
24
|
+
message: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>, readonly [{
|
|
26
|
+
readonly reason: "no_results";
|
|
27
|
+
readonly code: JsonRpcErrorCode.NotFound;
|
|
28
|
+
readonly when: "Query matched no authors.";
|
|
29
|
+
readonly recovery: "Check the spelling, try a partial name, or use an alternate name form.";
|
|
30
|
+
}]>;
|
|
31
|
+
//# sourceMappingURL=openlibrary-search-authors.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openlibrary-search-authors.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/openlibrary-search-authors.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;GAuGnC,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Search Open Library authors by name.
|
|
3
|
+
* @module mcp-server/tools/definitions/openlibrary-search-authors.tool
|
|
4
|
+
*/
|
|
5
|
+
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
import { getOpenLibraryService } from '../../../services/open-library/open-library-service.js';
|
|
8
|
+
export const openlibrarySearchAuthors = tool('openlibrary_search_authors', {
|
|
9
|
+
title: 'Search Authors',
|
|
10
|
+
description: 'Search Open Library authors by name. Returns Open Library Author IDs, names, birth/death dates, top works, and subject associations. Use author IDs for openlibrary_get_author (bio, remote IDs) or openlibrary_get_author_works (list of works).',
|
|
11
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
12
|
+
input: z.object({
|
|
13
|
+
query: z.string().describe('Author name search query. Partial names and alternate names work.'),
|
|
14
|
+
limit: z.number().int().min(1).max(100).default(10).describe('Max results to return.'),
|
|
15
|
+
offset: z.number().int().min(0).default(0).describe('Zero-based offset for pagination.'),
|
|
16
|
+
}),
|
|
17
|
+
output: z.object({
|
|
18
|
+
total: z.number().describe('Total matching authors across all pages.'),
|
|
19
|
+
authors: z
|
|
20
|
+
.array(z
|
|
21
|
+
.object({
|
|
22
|
+
author_id: z.string().describe('Open Library Author ID (OL…A).'),
|
|
23
|
+
name: z.string().describe('Primary author name.'),
|
|
24
|
+
alternate_names: z.array(z.string()).describe('Alternate or transliterated names.'),
|
|
25
|
+
birth_date: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('Birth date string. Absent when not recorded.'),
|
|
29
|
+
death_date: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('Death date string. Absent when not recorded.'),
|
|
33
|
+
top_work: z
|
|
34
|
+
.string()
|
|
35
|
+
.optional()
|
|
36
|
+
.describe("Title of the author's most popular work. Absent when unavailable."),
|
|
37
|
+
work_count: z.number().describe('Number of works catalogued for this author.'),
|
|
38
|
+
top_subjects: z
|
|
39
|
+
.array(z.string())
|
|
40
|
+
.describe("Most common subject tags across the author's works."),
|
|
41
|
+
ratings_average: z
|
|
42
|
+
.number()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe("Average community rating across the author's works. Absent when no ratings exist."),
|
|
45
|
+
})
|
|
46
|
+
.describe('A matching author record.'))
|
|
47
|
+
.describe('Matching authors, up to limit.'),
|
|
48
|
+
message: z
|
|
49
|
+
.string()
|
|
50
|
+
.optional()
|
|
51
|
+
.describe('Recovery hint when results are empty. Absent when results are found.'),
|
|
52
|
+
}),
|
|
53
|
+
errors: [
|
|
54
|
+
{
|
|
55
|
+
reason: 'no_results',
|
|
56
|
+
code: JsonRpcErrorCode.NotFound,
|
|
57
|
+
when: 'Query matched no authors.',
|
|
58
|
+
recovery: 'Check the spelling, try a partial name, or use an alternate name form.',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
async handler(input, ctx) {
|
|
62
|
+
ctx.log.info('Searching authors', { query: input.query, limit: input.limit });
|
|
63
|
+
const svc = getOpenLibraryService();
|
|
64
|
+
const result = await svc.searchAuthors(input.query, input.limit, input.offset, ctx);
|
|
65
|
+
if (result.authors.length === 0) {
|
|
66
|
+
return {
|
|
67
|
+
total: 0,
|
|
68
|
+
authors: [],
|
|
69
|
+
message: `No authors matched "${input.query}". Try a partial name, check spelling, or use an alternate name form.`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
},
|
|
74
|
+
format: (result) => {
|
|
75
|
+
const lines = [];
|
|
76
|
+
lines.push(`**Total:** ${result.total} | **Returned:** ${result.authors.length}`);
|
|
77
|
+
if (result.message) {
|
|
78
|
+
lines.push('');
|
|
79
|
+
lines.push(`> ${result.message}`);
|
|
80
|
+
}
|
|
81
|
+
for (const author of result.authors) {
|
|
82
|
+
lines.push('');
|
|
83
|
+
lines.push(`## ${author.name}`);
|
|
84
|
+
lines.push(`**Author ID:** ${author.author_id}`);
|
|
85
|
+
const meta = [];
|
|
86
|
+
if (author.birth_date)
|
|
87
|
+
meta.push(`Born: ${author.birth_date}`);
|
|
88
|
+
if (author.death_date)
|
|
89
|
+
meta.push(`Died: ${author.death_date}`);
|
|
90
|
+
meta.push(`Works: ${author.work_count}`);
|
|
91
|
+
if (author.ratings_average != null)
|
|
92
|
+
meta.push(`Rating: ${author.ratings_average.toFixed(1)}`);
|
|
93
|
+
if (meta.length)
|
|
94
|
+
lines.push(meta.join(' | '));
|
|
95
|
+
if (author.top_work)
|
|
96
|
+
lines.push(`**Top work:** ${author.top_work}`);
|
|
97
|
+
if (author.alternate_names.length)
|
|
98
|
+
lines.push(`**Alternate names:** ${author.alternate_names.join(', ')}`);
|
|
99
|
+
if (author.top_subjects.length)
|
|
100
|
+
lines.push(`**Top subjects:** ${author.top_subjects.slice(0, 5).join(', ')}`);
|
|
101
|
+
}
|
|
102
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=openlibrary-search-authors.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openlibrary-search-authors.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/openlibrary-search-authors.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAA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AAI,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC9F,IAAI,IAAI,CAAC,MAAM;gBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9C,IAAI,MAAM,CAAC,QAAQ;gBAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;YACpE,IAAI,MAAM,CAAC,eAAe,CAAC,MAAM;gBAC/B,KAAK,CAAC,IAAI,CAAC,wBAAwB,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC1E,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM;gBAC5B,KAAK,CAAC,IAAI,CAAC,qBAAqB,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClF,CAAC;QAED,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Full-text book search across Open Library works.
|
|
3
|
+
* @module mcp-server/tools/definitions/openlibrary-search-books.tool
|
|
4
|
+
*/
|
|
5
|
+
import { z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
export declare const openlibrarySearchBooks: import("@cyanheads/mcp-ts-core").ToolDefinition<z.ZodObject<{
|
|
8
|
+
query: z.ZodOptional<z.ZodString>;
|
|
9
|
+
title: z.ZodOptional<z.ZodString>;
|
|
10
|
+
author: z.ZodOptional<z.ZodString>;
|
|
11
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
12
|
+
publisher: z.ZodOptional<z.ZodString>;
|
|
13
|
+
isbn: z.ZodOptional<z.ZodString>;
|
|
14
|
+
language: z.ZodOptional<z.ZodString>;
|
|
15
|
+
sort: z.ZodDefault<z.ZodEnum<{
|
|
16
|
+
relevance: "relevance";
|
|
17
|
+
editions: "editions";
|
|
18
|
+
new: "new";
|
|
19
|
+
old: "old";
|
|
20
|
+
rating: "rating";
|
|
21
|
+
}>>;
|
|
22
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
23
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
24
|
+
include_availability: z.ZodDefault<z.ZodBoolean>;
|
|
25
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
26
|
+
total: z.ZodNumber;
|
|
27
|
+
offset: z.ZodNumber;
|
|
28
|
+
works: z.ZodArray<z.ZodObject<{
|
|
29
|
+
work_id: z.ZodString;
|
|
30
|
+
title: z.ZodString;
|
|
31
|
+
author_names: z.ZodArray<z.ZodString>;
|
|
32
|
+
author_ids: z.ZodArray<z.ZodString>;
|
|
33
|
+
first_publish_year: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
edition_count: z.ZodNumber;
|
|
35
|
+
cover_id: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
subjects: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
37
|
+
ebook_access: z.ZodEnum<{
|
|
38
|
+
no_ebook: "no_ebook";
|
|
39
|
+
printdisabled: "printdisabled";
|
|
40
|
+
borrowable: "borrowable";
|
|
41
|
+
public: "public";
|
|
42
|
+
}>;
|
|
43
|
+
has_fulltext: z.ZodBoolean;
|
|
44
|
+
ratings_average: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
availability: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
46
|
+
status: z.ZodString;
|
|
47
|
+
available_to_browse: z.ZodBoolean;
|
|
48
|
+
available_to_borrow: z.ZodBoolean;
|
|
49
|
+
available_to_waitlist: z.ZodBoolean;
|
|
50
|
+
is_readable: z.ZodBoolean;
|
|
51
|
+
is_lendable: z.ZodBoolean;
|
|
52
|
+
is_previewable: z.ZodBoolean;
|
|
53
|
+
is_restricted: z.ZodBoolean;
|
|
54
|
+
openlibrary_edition: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>>>;
|
|
56
|
+
ia_identifiers: z.ZodArray<z.ZodString>;
|
|
57
|
+
}, z.core.$strip>>;
|
|
58
|
+
message: z.ZodOptional<z.ZodString>;
|
|
59
|
+
}, z.core.$strip>, readonly [{
|
|
60
|
+
readonly reason: "no_results";
|
|
61
|
+
readonly code: JsonRpcErrorCode.NotFound;
|
|
62
|
+
readonly when: "Query matched no works.";
|
|
63
|
+
readonly recovery: "Broaden the query, check spelling, or try different search terms.";
|
|
64
|
+
}]>;
|
|
65
|
+
//# sourceMappingURL=openlibrary-search-books.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openlibrary-search-books.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/openlibrary-search-books.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyOjC,CAAC"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Full-text book search across Open Library works.
|
|
3
|
+
* @module mcp-server/tools/definitions/openlibrary-search-books.tool
|
|
4
|
+
*/
|
|
5
|
+
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
import { getOpenLibraryService } from '../../../services/open-library/open-library-service.js';
|
|
8
|
+
export const openlibrarySearchBooks = tool('openlibrary_search_books', {
|
|
9
|
+
title: 'Search Books',
|
|
10
|
+
description: 'Full-text book search across Open Library works. Supports field filters (title, author, subject, publisher, ISBN, language) and returns work-level records with edition counts, cover IDs, and reading availability. Use query for general search or combine specific field filters. Results are work-level — drill into editions via openlibrary_get_editions.',
|
|
11
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
12
|
+
input: z.object({
|
|
13
|
+
query: z
|
|
14
|
+
.string()
|
|
15
|
+
.optional()
|
|
16
|
+
.describe('Full-text search query. Supports Solr field prefixes: title:, author:, subject:, publisher:, isbn:, language:. Omit to use the filter parameters instead.'),
|
|
17
|
+
title: z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('Filter by title. Matched against work title and alternative titles.'),
|
|
21
|
+
author: z.string().optional().describe('Filter by author name. Partial names work.'),
|
|
22
|
+
subject: z
|
|
23
|
+
.string()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('Filter by subject tag (e.g., "science fiction", "history").'),
|
|
26
|
+
publisher: z
|
|
27
|
+
.string()
|
|
28
|
+
.optional()
|
|
29
|
+
.describe('Filter by publisher name. Partial names work (e.g., "Penguin").'),
|
|
30
|
+
isbn: z
|
|
31
|
+
.string()
|
|
32
|
+
.optional()
|
|
33
|
+
.describe('Find works that have editions with this ISBN (10 or 13 digits, hyphens ignored).'),
|
|
34
|
+
language: z
|
|
35
|
+
.string()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe('Two-letter ISO 639-1 language code (e.g., "en", "fr"). Influences but does not exclude results; use language:fr in query to hard-filter.'),
|
|
38
|
+
sort: z
|
|
39
|
+
.enum(['relevance', 'new', 'old', 'rating', 'editions'])
|
|
40
|
+
.default('relevance')
|
|
41
|
+
.describe('Sort order. "relevance" uses Solr scoring. "new"/"old" sort by first publish year. "rating" by average community rating. "editions" by edition count.'),
|
|
42
|
+
limit: z
|
|
43
|
+
.number()
|
|
44
|
+
.int()
|
|
45
|
+
.min(1)
|
|
46
|
+
.max(100)
|
|
47
|
+
.default(10)
|
|
48
|
+
.describe('Max results to return. Higher values increase response size; prefer 10–20 for exploration.'),
|
|
49
|
+
offset: z.number().int().min(0).default(0).describe('Zero-based offset for pagination.'),
|
|
50
|
+
include_availability: z
|
|
51
|
+
.boolean()
|
|
52
|
+
.default(false)
|
|
53
|
+
.describe('Include live reading availability from Internet Archive (borrow/read status). Adds ~200ms latency. Use when the user needs to know if they can read the book online.'),
|
|
54
|
+
}),
|
|
55
|
+
output: z.object({
|
|
56
|
+
total: z.number().describe('Total matching works across all pages.'),
|
|
57
|
+
offset: z.number().describe('Zero-based offset of the first returned result.'),
|
|
58
|
+
works: z
|
|
59
|
+
.array(z
|
|
60
|
+
.object({
|
|
61
|
+
work_id: z
|
|
62
|
+
.string()
|
|
63
|
+
.describe('Open Library Work ID (OL…W). Use for openlibrary_get_work or openlibrary_get_editions.'),
|
|
64
|
+
title: z.string().describe('Work title.'),
|
|
65
|
+
author_names: z.array(z.string()).describe('Author display names.'),
|
|
66
|
+
author_ids: z
|
|
67
|
+
.array(z.string())
|
|
68
|
+
.describe('Open Library Author IDs (OL…A) for follow-up lookups.'),
|
|
69
|
+
first_publish_year: z
|
|
70
|
+
.number()
|
|
71
|
+
.optional()
|
|
72
|
+
.describe('Year of first publication. Absent when unknown.'),
|
|
73
|
+
edition_count: z.number().describe('Total editions catalogued for this work.'),
|
|
74
|
+
cover_id: z
|
|
75
|
+
.number()
|
|
76
|
+
.optional()
|
|
77
|
+
.describe('Numeric cover ID. Pass to openlibrary_get_cover_url with id_type "id". Absent when no cover is available.'),
|
|
78
|
+
subjects: z
|
|
79
|
+
.array(z.string())
|
|
80
|
+
.optional()
|
|
81
|
+
.describe('Up to 5 subject tags. Absent when no subjects are tagged.'),
|
|
82
|
+
ebook_access: z
|
|
83
|
+
.enum(['no_ebook', 'printdisabled', 'borrowable', 'public'])
|
|
84
|
+
.describe('"public" = freely readable. "borrowable" = borrow on Internet Archive. "printdisabled" = access for print-disabled users. "no_ebook" = no digital version.'),
|
|
85
|
+
has_fulltext: z
|
|
86
|
+
.boolean()
|
|
87
|
+
.describe('True when a full-text version exists on Internet Archive.'),
|
|
88
|
+
ratings_average: z
|
|
89
|
+
.number()
|
|
90
|
+
.optional()
|
|
91
|
+
.describe('Average community rating (1–5). Absent when no ratings exist.'),
|
|
92
|
+
availability: z
|
|
93
|
+
.object({
|
|
94
|
+
status: z.string().describe('Availability status string from Internet Archive.'),
|
|
95
|
+
available_to_browse: z
|
|
96
|
+
.boolean()
|
|
97
|
+
.describe('True when the book can be browsed for free.'),
|
|
98
|
+
available_to_borrow: z.boolean().describe('True when the book can be borrowed.'),
|
|
99
|
+
available_to_waitlist: z.boolean().describe('True when a waitlist is available.'),
|
|
100
|
+
is_readable: z.boolean().describe('True when the book is freely readable online.'),
|
|
101
|
+
is_lendable: z.boolean().describe('True when the book can be lent.'),
|
|
102
|
+
is_previewable: z.boolean().describe('True when a limited preview is available.'),
|
|
103
|
+
is_restricted: z.boolean().describe('True when access is restricted.'),
|
|
104
|
+
openlibrary_edition: z
|
|
105
|
+
.string()
|
|
106
|
+
.optional()
|
|
107
|
+
.describe('Edition OLID the availability check was resolved against.'),
|
|
108
|
+
})
|
|
109
|
+
.nullable()
|
|
110
|
+
.optional()
|
|
111
|
+
.describe('Live reading availability from Internet Archive. Present when include_availability is true and the work has an Internet Archive item. Null when include_availability is true but no IA item exists.'),
|
|
112
|
+
ia_identifiers: z
|
|
113
|
+
.array(z.string())
|
|
114
|
+
.describe('Internet Archive item identifiers associated with this work.'),
|
|
115
|
+
})
|
|
116
|
+
.describe('A work-level result from the search.'))
|
|
117
|
+
.describe('Matching works, up to limit.'),
|
|
118
|
+
message: z
|
|
119
|
+
.string()
|
|
120
|
+
.optional()
|
|
121
|
+
.describe('Recovery hint when results are empty — echoes the search criteria and suggests how to broaden. Absent when results are found.'),
|
|
122
|
+
}),
|
|
123
|
+
errors: [
|
|
124
|
+
{
|
|
125
|
+
reason: 'no_results',
|
|
126
|
+
code: JsonRpcErrorCode.NotFound,
|
|
127
|
+
when: 'Query matched no works.',
|
|
128
|
+
recovery: 'Broaden the query, check spelling, or try different search terms.',
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
async handler(input, ctx) {
|
|
132
|
+
ctx.log.info('Searching books', {
|
|
133
|
+
query: input.query,
|
|
134
|
+
title: input.title,
|
|
135
|
+
author: input.author,
|
|
136
|
+
subject: input.subject,
|
|
137
|
+
limit: input.limit,
|
|
138
|
+
offset: input.offset,
|
|
139
|
+
});
|
|
140
|
+
const svc = getOpenLibraryService();
|
|
141
|
+
const result = await svc.searchBooks(input, ctx);
|
|
142
|
+
if (result.works.length === 0) {
|
|
143
|
+
const terms = [];
|
|
144
|
+
if (input.query)
|
|
145
|
+
terms.push(`query "${input.query}"`);
|
|
146
|
+
if (input.title)
|
|
147
|
+
terms.push(`title "${input.title}"`);
|
|
148
|
+
if (input.author)
|
|
149
|
+
terms.push(`author "${input.author}"`);
|
|
150
|
+
if (input.subject)
|
|
151
|
+
terms.push(`subject "${input.subject}"`);
|
|
152
|
+
const hint = terms.length
|
|
153
|
+
? `No works matched ${terms.join(', ')}. Try broader or different terms.`
|
|
154
|
+
: 'No works matched your search. Try different filters or a general query.';
|
|
155
|
+
return {
|
|
156
|
+
total: 0,
|
|
157
|
+
offset: result.offset,
|
|
158
|
+
works: [],
|
|
159
|
+
message: hint,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return { total: result.total, offset: result.offset, works: result.works };
|
|
163
|
+
},
|
|
164
|
+
format: (result) => {
|
|
165
|
+
const lines = [];
|
|
166
|
+
lines.push(`**Total results:** ${result.total} | **Offset:** ${result.offset} | **Returned:** ${result.works.length}`);
|
|
167
|
+
if (result.message) {
|
|
168
|
+
lines.push('');
|
|
169
|
+
lines.push(`> ${result.message}`);
|
|
170
|
+
}
|
|
171
|
+
for (const work of result.works) {
|
|
172
|
+
lines.push('');
|
|
173
|
+
lines.push(`## ${work.title}`);
|
|
174
|
+
lines.push(`**Work ID:** ${work.work_id}`);
|
|
175
|
+
if (work.author_names.length) {
|
|
176
|
+
lines.push(`**Authors:** ${work.author_names.join(', ')} (IDs: ${work.author_ids.join(', ')})`);
|
|
177
|
+
}
|
|
178
|
+
const meta = [];
|
|
179
|
+
if (work.first_publish_year != null)
|
|
180
|
+
meta.push(`First published: ${work.first_publish_year}`);
|
|
181
|
+
meta.push(`Editions: ${work.edition_count}`);
|
|
182
|
+
meta.push(`E-book: ${work.ebook_access}`);
|
|
183
|
+
if (work.has_fulltext)
|
|
184
|
+
meta.push('Has full text');
|
|
185
|
+
if (work.ratings_average != null)
|
|
186
|
+
meta.push(`Rating: ${work.ratings_average.toFixed(1)}`);
|
|
187
|
+
lines.push(meta.join(' | '));
|
|
188
|
+
if (work.cover_id != null)
|
|
189
|
+
lines.push(`**Cover ID:** ${work.cover_id}`);
|
|
190
|
+
if (work.subjects?.length)
|
|
191
|
+
lines.push(`**Subjects:** ${work.subjects.join(', ')}`);
|
|
192
|
+
if (work.ia_identifiers.length)
|
|
193
|
+
lines.push(`**IA:** ${work.ia_identifiers.join(', ')}`);
|
|
194
|
+
if (work.availability != null) {
|
|
195
|
+
const avParts = [
|
|
196
|
+
`Status: ${work.availability.status}`,
|
|
197
|
+
`Browse: ${work.availability.available_to_browse}`,
|
|
198
|
+
`Borrow: ${work.availability.available_to_borrow}`,
|
|
199
|
+
`Waitlist: ${work.availability.available_to_waitlist}`,
|
|
200
|
+
`Read: ${work.availability.is_readable}`,
|
|
201
|
+
`Lend: ${work.availability.is_lendable}`,
|
|
202
|
+
`Preview: ${work.availability.is_previewable}`,
|
|
203
|
+
`Restricted: ${work.availability.is_restricted}`,
|
|
204
|
+
];
|
|
205
|
+
if (work.availability.openlibrary_edition) {
|
|
206
|
+
avParts.push(`Edition: ${work.availability.openlibrary_edition}`);
|
|
207
|
+
}
|
|
208
|
+
lines.push(`**Availability:** ${avParts.join(' | ')}`);
|
|
209
|
+
}
|
|
210
|
+
else if (work.availability === null) {
|
|
211
|
+
lines.push('**Availability:** No Internet Archive item found.');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
//# sourceMappingURL=openlibrary-search-books.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openlibrary-search-books.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/openlibrary-search-books.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAExF,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,0BAA0B,EAAE;IACrE,KAAK,EAAE,cAAc;IACrB,WAAW,EACT,iWAAiW;IACnW,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE;IACxD,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,KAAK,EAAE,CAAC;aACL,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CACP,2JAA2J,CAC5J;QACH,KAAK,EAAE,CAAC;aACL,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,qEAAqE,CAAC;QAClF,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;QACpF,OAAO,EAAE,CAAC;aACP,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,6DAA6D,CAAC;QAC1E,SAAS,EAAE,CAAC;aACT,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAA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AC,mBAAmB,EAAE,CAAC,CAAC;gBACpE,CAAC;gBACD,KAAK,CAAC,IAAI,CAAC,qBAAqB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACzD,CAAC;iBAAM,IAAI,IAAI,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;gBACtC,KAAK,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;QAED,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Open Library REST API client. Handles search, works, editions, authors,
|
|
3
|
+
* subjects, and cover URL construction with retry and timeout.
|
|
4
|
+
* @module services/open-library/open-library-service
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@cyanheads/mcp-ts-core';
|
|
7
|
+
import type { AuthorDetail, AuthorSearchResult, AuthorWork, EditionDetail, EditionIdType, EditionSummary, SearchWork, SubjectWork, WorkDetail } from './types.js';
|
|
8
|
+
export declare class OpenLibraryService {
|
|
9
|
+
private readonly userAgent;
|
|
10
|
+
constructor(userAgent: string);
|
|
11
|
+
private headers;
|
|
12
|
+
private fetch;
|
|
13
|
+
searchBooks(params: {
|
|
14
|
+
query?: string | undefined;
|
|
15
|
+
title?: string | undefined;
|
|
16
|
+
author?: string | undefined;
|
|
17
|
+
subject?: string | undefined;
|
|
18
|
+
publisher?: string | undefined;
|
|
19
|
+
isbn?: string | undefined;
|
|
20
|
+
language?: string | undefined;
|
|
21
|
+
sort?: string | undefined;
|
|
22
|
+
limit: number;
|
|
23
|
+
offset: number;
|
|
24
|
+
include_availability?: boolean | undefined;
|
|
25
|
+
}, ctx: Context): Promise<{
|
|
26
|
+
total: number;
|
|
27
|
+
offset: number;
|
|
28
|
+
works: SearchWork[];
|
|
29
|
+
}>;
|
|
30
|
+
getWork(workId: string, ctx: Context): Promise<WorkDetail>;
|
|
31
|
+
getEditions(workId: string, limit: number, offset: number, ctx: Context): Promise<{
|
|
32
|
+
total: number;
|
|
33
|
+
work_id: string;
|
|
34
|
+
editions: EditionSummary[];
|
|
35
|
+
}>;
|
|
36
|
+
getEditionByIdentifier(identifier: string, idType: EditionIdType, ctx: Context): Promise<EditionDetail>;
|
|
37
|
+
searchAuthors(query: string, limit: number, offset: number, ctx: Context): Promise<{
|
|
38
|
+
total: number;
|
|
39
|
+
authors: AuthorSearchResult[];
|
|
40
|
+
}>;
|
|
41
|
+
getAuthor(authorId: string, ctx: Context): Promise<AuthorDetail>;
|
|
42
|
+
getAuthorWorks(authorId: string, limit: number, offset: number, ctx: Context): Promise<{
|
|
43
|
+
total: number;
|
|
44
|
+
author_id: string;
|
|
45
|
+
works: AuthorWork[];
|
|
46
|
+
}>;
|
|
47
|
+
getSubject(subject: string, limit: number, offset: number, ebooksOnly: boolean, ctx: Context): Promise<{
|
|
48
|
+
subject_name: string;
|
|
49
|
+
subject_key: string;
|
|
50
|
+
work_count: number;
|
|
51
|
+
works: SubjectWork[];
|
|
52
|
+
}>;
|
|
53
|
+
getCoverUrl(identifier: string, idType: 'id' | 'isbn' | 'olid', target: 'book' | 'author', size: 'S' | 'M' | 'L'): string;
|
|
54
|
+
}
|
|
55
|
+
export declare function initOpenLibraryService(): void;
|
|
56
|
+
export declare function getOpenLibraryService(): OpenLibraryService;
|
|
57
|
+
//# sourceMappingURL=open-library-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-library-service.d.ts","sourceRoot":"","sources":["../../../src/services/open-library/open-library-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAItD,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,aAAa,E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