ailibrary-mcp 1.0.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/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # ailibrary-mcp
2
+
3
+ [![npm version](https://img.shields.io/npm/v/ailibrary-mcp.svg)](https://www.npmjs.com/package/ailibrary-mcp)
4
+ [![npm downloads](https://img.shields.io/npm/dm/ailibrary-mcp.svg)](https://www.npmjs.com/package/ailibrary-mcp)
5
+
6
+ MCP (Model Context Protocol) server for [AILibrary](https://ailibrary-m43k.polsia.app) — the AI-native media asset library.
7
+
8
+ Gives AI agents the ability to **search, discover, and download** licensed videos, images, and audio clips autonomously, with automatic credit billing.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npx -y ailibrary-mcp
14
+ ```
15
+
16
+ Or install globally:
17
+
18
+ ```bash
19
+ npm install -g ailibrary-mcp
20
+ ```
21
+
22
+ ## Configuration
23
+
24
+ Add to your MCP client config (Claude Desktop, Cursor, Windsurf, Cline, etc.):
25
+
26
+ ### Using environment variable (recommended)
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "ailibrary": {
32
+ "command": "npx",
33
+ "args": ["-y", "ailibrary-mcp"],
34
+ "env": {
35
+ "AILIBRARY_API_KEY": "alib_your_key_here"
36
+ }
37
+ }
38
+ }
39
+ }
40
+ ```
41
+
42
+ ### Passing API key per tool call
43
+
44
+ ```json
45
+ {
46
+ "mcpServers": {
47
+ "ailibrary": {
48
+ "command": "npx",
49
+ "args": ["-y", "ailibrary-mcp"]
50
+ }
51
+ }
52
+ }
53
+ ```
54
+
55
+ Then pass `api_key` in each tool call directly.
56
+
57
+ Get an API key at [ailibrary-m43k.polsia.app](https://ailibrary-m43k.polsia.app).
58
+
59
+ ## Tools
60
+
61
+ | Tool | Description |
62
+ |------|-------------|
63
+ | `search_assets` | Search the media library by keyword, with optional type filter (`video`, `image`, `audio`) |
64
+ | `download_asset` | Download an asset by ID (deducts credits from your balance) |
65
+ | `check_balance` | Check your remaining credit balance |
66
+
67
+ ## Usage Example
68
+
69
+ Once connected, your AI agent can:
70
+
71
+ ```
72
+ Search for 3 drone nature videos suitable for a product intro
73
+ → Uses search_assets({ api_key: "alib_...", query: "drone nature", type: "video" })
74
+
75
+ Download the best match
76
+ → Uses download_asset({ api_key: "alib_...", asset_id: 42 })
77
+
78
+ Check remaining credits
79
+ → Uses check_balance({ api_key: "alib_..." })
80
+ ```
81
+
82
+ ## API Reference
83
+
84
+ All tools accept an `api_key` parameter (or read `AILIBRARY_API_KEY` from the environment).
85
+
86
+ ### `search_assets`
87
+
88
+ | Parameter | Type | Required | Description |
89
+ |-----------|------|----------|-------------|
90
+ | `api_key` | string | yes* | Your AILibrary API key |
91
+ | `query` | string | yes | Search terms |
92
+ | `type` | string | no | Filter by type: `video`, `image`, `audio` |
93
+ | `limit` | number | no | Max results (default: 10) |
94
+
95
+ ### `download_asset`
96
+
97
+ | Parameter | Type | Required | Description |
98
+ |-----------|------|----------|-------------|
99
+ | `api_key` | string | yes* | Your AILibrary API key |
100
+ | `asset_id` | number | yes | ID from search results |
101
+
102
+ ### `check_balance`
103
+
104
+ | Parameter | Type | Required | Description |
105
+ |-----------|------|----------|-------------|
106
+ | `api_key` | string | yes* | Your AILibrary API key |
107
+
108
+ *\* Or set `AILIBRARY_API_KEY` environment variable*
109
+
110
+ ## License
111
+
112
+ MIT
113
+
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { ListToolsRequestSchema, CallToolRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
+ const API_BASE_URL = "https://ailibrary-m43k.polsia.app";
6
+ // ── HTTP helper ───────────────────────────────────────────────────────────────
7
+ async function apiPost(path, apiKey, body) {
8
+ const response = await fetch(`${API_BASE_URL}${path}`, {
9
+ method: "POST",
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ "x-api-key": apiKey,
13
+ },
14
+ body: JSON.stringify(body),
15
+ });
16
+ if (!response.ok) {
17
+ const err = (await response
18
+ .json()
19
+ .catch(() => ({ error: response.statusText })));
20
+ throw new Error(`AILibrary API error ${response.status}: ${err.error ?? JSON.stringify(err)}`);
21
+ }
22
+ return response.json();
23
+ }
24
+ // ── Server setup ──────────────────────────────────────────────────────────────
25
+ const server = new Server({ name: "ailibrary", version: "1.0.0" }, { capabilities: { tools: {} } });
26
+ // ── tools/list ────────────────────────────────────────────────────────────────
27
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
28
+ tools: [
29
+ {
30
+ name: "search_assets",
31
+ description: "Search the AILibrary media library for videos, images, and audio. " +
32
+ "Returns assets with IDs, titles, types, preview URLs, and credit costs. " +
33
+ "Use the asset ID from results to call download_asset.",
34
+ inputSchema: {
35
+ type: "object",
36
+ properties: {
37
+ api_key: {
38
+ type: "string",
39
+ description: "Your AILibrary API key (starts with 'alib_')",
40
+ },
41
+ query: {
42
+ type: "string",
43
+ description: "Search query (e.g. 'office background', 'nature drone shot', 'upbeat corporate music')",
44
+ },
45
+ type: {
46
+ type: "string",
47
+ enum: ["video", "image", "audio"],
48
+ description: "Filter by asset type (optional)",
49
+ },
50
+ limit: {
51
+ type: "number",
52
+ description: "Max results (default 20, max 100)",
53
+ },
54
+ },
55
+ required: ["api_key", "query"],
56
+ },
57
+ },
58
+ {
59
+ name: "download_asset",
60
+ description: "Download a specific media asset by its ID. Deducts credits from your balance and returns the download URL.",
61
+ inputSchema: {
62
+ type: "object",
63
+ properties: {
64
+ api_key: {
65
+ type: "string",
66
+ description: "Your AILibrary API key",
67
+ },
68
+ asset_id: {
69
+ type: "number",
70
+ description: "Asset ID obtained from search_assets results",
71
+ },
72
+ },
73
+ required: ["api_key", "asset_id"],
74
+ },
75
+ },
76
+ {
77
+ name: "check_balance",
78
+ description: "Verify your AILibrary API key and check that it's working. Returns confirmation that the key is valid.",
79
+ inputSchema: {
80
+ type: "object",
81
+ properties: {
82
+ api_key: {
83
+ type: "string",
84
+ description: "Your AILibrary API key",
85
+ },
86
+ },
87
+ required: ["api_key"],
88
+ },
89
+ },
90
+ ],
91
+ }));
92
+ // ── tools/call ────────────────────────────────────────────────────────────────
93
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
94
+ const { name, arguments: args } = request.params;
95
+ if (!args) {
96
+ return {
97
+ content: [{ type: "text", text: "Error: no arguments provided" }],
98
+ isError: true,
99
+ };
100
+ }
101
+ try {
102
+ switch (name) {
103
+ case "search_assets": {
104
+ const { api_key, query, type, limit } = args;
105
+ if (!api_key)
106
+ throw new Error("api_key is required");
107
+ if (!query)
108
+ throw new Error("query is required");
109
+ const body = { query };
110
+ if (type !== undefined)
111
+ body["type"] = type;
112
+ if (limit !== undefined)
113
+ body["limit"] = limit;
114
+ const result = await apiPost("/v1/assets/search", api_key, body);
115
+ return {
116
+ content: [
117
+ { type: "text", text: JSON.stringify(result, null, 2) },
118
+ ],
119
+ };
120
+ }
121
+ case "download_asset": {
122
+ const { api_key, asset_id } = args;
123
+ if (!api_key)
124
+ throw new Error("api_key is required");
125
+ if (asset_id === undefined || asset_id === null)
126
+ throw new Error("asset_id is required");
127
+ const result = await apiPost(`/v1/assets/${asset_id}/download`, api_key, {});
128
+ return {
129
+ content: [
130
+ { type: "text", text: JSON.stringify(result, null, 2) },
131
+ ],
132
+ };
133
+ }
134
+ case "check_balance": {
135
+ const { api_key } = args;
136
+ if (!api_key)
137
+ throw new Error("api_key is required");
138
+ // Use a minimal search to verify the key works
139
+ await apiPost("/v1/assets/search", api_key, {
140
+ query: "a",
141
+ limit: 1,
142
+ });
143
+ return {
144
+ content: [
145
+ {
146
+ type: "text",
147
+ text: JSON.stringify({
148
+ valid: true,
149
+ message: "API key is valid. Use search_assets to find media assets.",
150
+ }, null, 2),
151
+ },
152
+ ],
153
+ };
154
+ }
155
+ default:
156
+ return {
157
+ content: [
158
+ {
159
+ type: "text",
160
+ text: `Unknown tool: ${name}`,
161
+ },
162
+ ],
163
+ isError: true,
164
+ };
165
+ }
166
+ }
167
+ catch (error) {
168
+ const message = error instanceof Error ? error.message : String(error);
169
+ return {
170
+ content: [{ type: "text", text: `Error: ${message}` }],
171
+ isError: true,
172
+ };
173
+ }
174
+ });
175
+ // ── Connect and run ───────────────────────────────────────────────────────────
176
+ const transport = new StdioServerTransport();
177
+ await server.connect(transport);
178
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAE5C,MAAM,YAAY,GAAG,mCAAmC,CAAC;AAmCzD,iFAAiF;AAEjF,KAAK,UAAU,OAAO,CACpB,IAAY,EACZ,MAAc,EACd,IAA6B;IAE7B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,YAAY,GAAG,IAAI,EAAE,EAAE;QACrD,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,WAAW,EAAE,MAAM;SACpB;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;KAC3B,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,GAAG,GAAG,CAAC,MAAM,QAAQ;aACxB,IAAI,EAAE;aACN,KAAK,CAAC,GAAG,EAAE,CAAC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M,OAAO,CAAiB,mBAAmB,EAAE,OAAO,EAAE;oBAC1D,KAAK,EAAE,GAAG;oBACV,KAAK,EAAE,CAAC;iBACT,CAAC,CAAC;gBACH,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB;gCACE,KAAK,EAAE,IAAI;gCACX,OAAO,EACL,2DAA2D;6BAC9D,EACD,IAAI,EACJ,CAAC,CACF;yBACF;qBACF;iBACF,CAAC;YACJ,CAAC;YAED;gBACE,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,iBAAiB,IAAI,EAAE;yBAC9B;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;QACN,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,UAAU,OAAO,EAAE,EAAE,CAAC;YAC/D,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,iFAAiF;AAEjF,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;AAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "ailibrary-mcp",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for AILibrary - AI-native video and media asset library",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "ailibrary-mcp": "dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build",
13
+ "start": "node dist/index.js"
14
+ },
15
+ "keywords": [
16
+ "mcp",
17
+ "model-context-protocol",
18
+ "ai",
19
+ "media",
20
+ "video",
21
+ "assets",
22
+ "library"
23
+ ],
24
+ "author": "AILibrary",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/Polsia-Inc/ailibrary.git",
29
+ "directory": "mcp-server"
30
+ },
31
+ "homepage": "https://ailibrary-m43k.polsia.app",
32
+ "dependencies": {
33
+ "@modelcontextprotocol/sdk": "^1.6.1"
34
+ },
35
+ "devDependencies": {
36
+ "typescript": "^5.3.3",
37
+ "@types/node": "^20.11.0"
38
+ },
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "files": [
46
+ "dist",
47
+ "README.md"
48
+ ]
49
+ }