Skip to content

Commit f3d3e0e

Browse files
authored
Refactor and readme fixes; Check api key on startup (#12)
1 parent b62309f commit f3d3e0e

File tree

11 files changed

+313
-250
lines changed

11 files changed

+313
-250
lines changed

.vscode/mcp.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"servers": {
3+
"plainly": {
4+
"command": "yarn",
5+
"args": [
6+
"dlx",
7+
"@plainly-videos/mcp-server@latest",
8+
"mcp-server"
9+
],
10+
"env": {
11+
"PLAINLY_API_KEY": "<PLAINLY_API_KEY>"
12+
}
13+
}
14+
}
15+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Implementation of MCP server for [Plainly](https://www.plainlyvideos.com/) in No
3030
{
3131
"servers": {
3232
"plainly": {
33-
"command": "npx",
34-
"args": ["-y", "@plainly-videos/mcp-server@latest"],
33+
"command": "yarn",
34+
"args": ["dlx", "@plainly-videos/mcp-server@latest", "mcp-server"],
3535
"env": {
3636
"PLAINLY_API_KEY": "<PLAINLY_API_KEY>"
3737
}

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@plainly-videos/mcp-server",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "MCP server for Plainly Videos that allows browsing designs and projects, as well as rendering videos.",
55
"license": "MIT",
66
"author": "PlainlyVideos <[email protected]>",
@@ -19,8 +19,15 @@
1919
"mcp-server",
2020
"modelcontextprotocol",
2121
"aftereffects",
22+
"adobe-after-effects",
2223
"video-api",
23-
"video-automation"
24+
"video-automation",
25+
"video-processing",
26+
"video-rendering",
27+
"automation",
28+
"api",
29+
"javascript",
30+
"typescript"
2431
],
2532
"bin": "dist/index.js",
2633
"files": [

src/axiosConfig.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios, { AxiosInstance } from "axios";
22
import env from "./env";
3+
import { PACKAGE_NAME, PACKAGE_VERSION } from "./contants";
34

45
export function createAxiosInstance(config?: {
56
baseUrl?: string;
@@ -15,7 +16,7 @@ export function createAxiosInstance(config?: {
1516
password: "",
1617
},
1718
headers: {
18-
"User-Agent": "plainly-mcp-server/1.0",
19+
"User-Agent": `${PACKAGE_NAME}/${PACKAGE_VERSION}`,
1920
},
2021
timeout: 10000,
2122
});

src/contants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { name, version } from "../package.json";
2+
3+
export const PACKAGE_NAME = name;
4+
export const PACKAGE_VERSION = version;

src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
import { PlainlyMcpServer } from "./server";
44
import env from "./env";
5+
import { isValidApiKey } from "./sdk";
56

67
// Validate required environment variables
7-
if (!env.PLAINLY_API_KEY || !env.PLAINLY_API_URL) {
8-
console.error(
9-
"Please set PLAINLY_API_KEY and PLAINLY_API_URL environment variables."
10-
);
8+
if (!env.PLAINLY_API_KEY) {
9+
console.error("\nERROR: PLAINLY_API_KEY environment variable is required.\n");
1110
process.exit(1);
11+
} else {
12+
// Test API key
13+
if (!(await isValidApiKey())) {
14+
console.error("\nERROR: Invalid PLAINLY_API_KEY.\n");
15+
process.exit(1);
16+
}
1217
}
1318

1419
const server = new PlainlyMcpServer();

src/sdk/api/checkApiKey.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createAxiosInstance } from "../../axiosConfig";
2+
3+
const api = createAxiosInstance();
4+
5+
export const isValidApiKey = async (): Promise<boolean> => {
6+
try {
7+
await api.get(`/api/v2/me`);
8+
return true;
9+
} catch {
10+
return false;
11+
}
12+
};

src/sdk/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./checkApiKey";
12
export * from "./listRenderableItems";
23
export * from "./getRenderableItemDetails";
34
export * from "./renderItem";

src/sdk/api/renderItem.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { AxiosResponse } from "axios";
22
import { createAxiosInstance } from "../../axiosConfig";
33
import { ProjectRenderDto, Render } from "../types";
4-
5-
// get name from package.json
6-
import { name } from "../../../package.json";
4+
import { PACKAGE_NAME } from "../../contants";
75

86
const api = createAxiosInstance();
97

@@ -24,7 +22,7 @@ export const renderItem = async (params: RenderParams): Promise<Render> => {
2422
templateId: params.templateVariantId,
2523
parameters: params.parameters,
2624
attributes: {
27-
[name]: "true",
25+
[PACKAGE_NAME]: "true",
2826
},
2927
});
3028

src/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import {
66
registerRenderItem,
77
registerCheckRenderStatus,
88
} from "./tools";
9+
import { PACKAGE_NAME, PACKAGE_VERSION } from "./contants";
910

1011
export class PlainlyMcpServer {
1112
server: McpServer;
1213
transport: StdioServerTransport;
1314

1415
constructor() {
1516
this.server = new McpServer({
16-
name: "plainly-mcp-server",
17-
version: "1.0.0",
17+
name: PACKAGE_NAME,
18+
version: PACKAGE_VERSION,
1819
});
1920
this.transport = new StdioServerTransport();
2021

0 commit comments

Comments
 (0)