Skip to content

Commit 2dfd2dc

Browse files
committed
Update tools
Add option to create language Change create translation key to bulk Remove single update for translation
1 parent e66b40b commit 2dfd2dc

File tree

6 files changed

+66
-60
lines changed

6 files changed

+66
-60
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@simplelocalize/simplelocalize-mcp",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "MCP Server for SimpleLocalize",
55
"license": "Apache-2.0",
66
"repository": "https://github.com/simplelocalize/simplelocalize-mcp-server",

src/api.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
2-
createTranslationKey,
3-
updateTranslationKey,
2+
createTranslationKeyBulk,
43
updateTranslationsBulk,
54
getAllTranslationKeys,
65
getTranslationKeyDetails,
76
getTags,
87
createTag,
98
getLanguages,
109
getTranslations,
10+
createLanguage,
1111
} from "./functions.js";
1212

1313
class SimpleLocalizeAPI {
@@ -19,11 +19,11 @@ class SimpleLocalizeAPI {
1919

2020
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2121
async run(method: string, arg: any) {
22-
if (method === "create_translation_key") {
23-
const output = JSON.stringify(await createTranslationKey(this.apiKey, arg));
22+
if (method === "create_language") {
23+
const output = JSON.stringify(await createLanguage(this.apiKey, arg));
2424
return output;
25-
} else if (method === "update_translation_key") {
26-
const output = JSON.stringify(await updateTranslationKey(this.apiKey, arg));
25+
} else if (method === "create_translation_key_bulk") {
26+
const output = JSON.stringify(await createTranslationKeyBulk(this.apiKey, arg));
2727
return output;
2828
} else if (method === "update_translations_bulk") {
2929
const output = JSON.stringify(await updateTranslationsBulk(this.apiKey, arg));

src/functions.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import { z } from "zod";
22
import axios from "axios";
33
import {
4-
createTranslationKeyParameters,
4+
createTranslationKeyBulkParameters,
55
updateTranslationKeyParameters,
66
updateTranslationsBulkParameters,
77
getTranslationKeyDetailsParameters,
88
createTagParameters,
99
getTranslationsParameters,
10+
createLanguageParameters,
1011
} from "./parameters.js";
1112

1213
const BASE_URL = "https://api.simplelocalize.io";
1314
const CLIENT_NAME = "mcp-server";
1415

15-
export const createTranslationKey = async (apiKey: string, params: z.infer<typeof createTranslationKeyParameters>) => {
16+
export const createTranslationKeyBulk = async (apiKey: string, params: z.infer<typeof createTranslationKeyBulkParameters>) => {
1617
try {
1718
const response = await axios.post(
18-
`${BASE_URL}/api/v1/translation-keys`,
19+
`${BASE_URL}/api/v1/translation-keys/bulk`,
1920
params,
2021
{
2122
headers: {
@@ -30,25 +31,6 @@ export const createTranslationKey = async (apiKey: string, params: z.infer<typeo
3031
}
3132
};
3233

33-
export const updateTranslationKey = async (apiKey: string, params: z.infer<typeof updateTranslationKeyParameters>) => {
34-
try {
35-
const { key, namespace, ...body } = params;
36-
const response = await axios.patch(
37-
`${BASE_URL}/api/v1/translation-keys?key=${encodeURIComponent(key)}${namespace ? `&namespace=${encodeURIComponent(namespace)}` : ""}`,
38-
body,
39-
{
40-
headers: {
41-
"X-SimpleLocalize-Token": apiKey,
42-
"X-SimpleLocalize-Client": CLIENT_NAME,
43-
},
44-
}
45-
);
46-
return response?.data;
47-
} catch (error) {
48-
return error;
49-
}
50-
};
51-
5234
export const updateTranslationsBulk = async (apiKey: string, params: z.infer<typeof updateTranslationsBulkParameters>) => {
5335
try {
5436
const response = await axios.patch(
@@ -171,3 +153,21 @@ export const getTranslations = async (apiKey: string, params: z.infer<typeof get
171153
return error;
172154
}
173155
};
156+
157+
export const createLanguage = async (apiKey: string, params: z.infer<typeof createLanguageParameters>) => {
158+
try {
159+
const response = await axios.post(
160+
`${BASE_URL}/api/v1/languages`,
161+
params,
162+
{
163+
headers: {
164+
"X-SimpleLocalize-Token": apiKey,
165+
"X-SimpleLocalize-Client": CLIENT_NAME,
166+
},
167+
}
168+
);
169+
return response?.data;
170+
} catch (error) {
171+
return error;
172+
}
173+
};

src/parameters.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { z } from "zod";
22

3-
export const createTranslationKeyParameters = z.object({
4-
key: z.string().describe("The translation key name. Must be unique within the namespace."),
5-
namespace: z.string().optional().describe("The namespace for the translation key. Defaults to an empty string if not provided."),
6-
description: z.string().optional().describe("A description of the translation key."),
7-
codeDescription: z.string().optional().describe("A description of the code context for the translation key."),
8-
tags: z.array(z.string().describe("A tag for the translation key.")).optional().describe("Tags to categorize the translation key."),
9-
charactersLimit: z.number().min(-1).optional().describe("The character limit for the translation key value. -1 means unlimited."),
3+
export const createTranslationKeyBulkParameters = z.object({
4+
translationKeys: z.array(z.object({
5+
key: z.string().describe("The translation key name. Must be unique within the namespace."),
6+
namespace: z.string().optional().describe("The namespace for the translation key. Defaults to an empty string if not provided."),
7+
description: z.string().optional().describe("A description of the translation key."),
8+
codeDescription: z.string().optional().describe("A description of the code context for the translation key."),
9+
tags: z.array(z.string().describe("A tag for the translation key.")).optional().describe("Tags to categorize the translation key."),
10+
charactersLimit: z.number().min(-1).optional().describe("The character limit for the translation key value. -1 means unlimited."),
11+
})).max(100).describe("Array of translation keys to create (max 100)."),
1012
});
1113

1214
export const updateTranslationKeyParameters = z.object({
@@ -45,6 +47,11 @@ export const createTagParameters = z.object({
4547

4648
export const getLanguagesParameters = z.object({}).describe("No parameters required.");
4749

50+
export const createLanguageParameters = z.object({
51+
key: z.string().describe("The language key (e.g. en, pl_PL)."),
52+
name: z.string().optional().describe("The language name (optional, e.g. English, Polish)."),
53+
});
54+
4855
export const getTranslationsParameters = z.object({
4956
key: z.string().optional().describe("Filter by translation key name."),
5057
namespace: z.string().optional().describe("Filter by namespace."),

src/prompts.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
export const createTranslationKeyPrompt = `
2-
This tool will create a new translation key in your SimpleLocalize project.
3-
- 'key' is required and must be unique within the namespace.
4-
- 'namespace', 'description', 'codeDescription', 'tags', and 'charactersLimit' are optional.
5-
- Use 'charactersLimit' to restrict the length of translation values, or set to -1 for unlimited.
6-
`;
7-
8-
export const updateTranslationKeyPrompt = `
9-
This tool will update an existing translation key in your SimpleLocalize project.
10-
- Provide 'key' (required) and optionally 'namespace'.
11-
- You can update 'description', 'codeDescription', 'tags', and 'charactersLimit'.
12-
- Fields left empty or null will not be updated.
2+
This tool will create multiple translation keys in your SimpleLocalize project in bulk.
3+
- Provide an array of translation key objects (max 100).
4+
- Each object must include 'key' and can include 'namespace', 'description', 'codeDescription', 'tags', and 'charactersLimit'.
5+
- It doesn't throw an error if translation key already exists, but it returns a list of failures.
136
`;
147

158
export const updateTranslationsBulkPrompt = `
@@ -56,3 +49,9 @@ This tool will list translations in your SimpleLocalize project.
5649
- Supports pagination with 'page' and 'size'.
5750
- Use 'text' to search for translations containing a specific value (min 3 characters).
5851
`;
52+
53+
export const createLanguagePrompt = `
54+
This tool will create a new language in your SimpleLocalize project.
55+
- 'key' is required and must be a valid language key (e.g. en, pl_PL).
56+
- 'name' is optional and can be used to provide a display name for the language.
57+
`;

src/tools.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import { z } from "zod";
22
import {
3-
createTranslationKeyParameters,
4-
updateTranslationKeyParameters,
3+
createTranslationKeyBulkParameters,
54
updateTranslationsBulkParameters,
65
getAllTranslationKeysParameters,
76
getTranslationKeyDetailsParameters,
87
getTagsParameters,
98
createTagParameters,
109
getLanguagesParameters,
1110
getTranslationsParameters,
11+
createLanguageParameters,
1212
} from "./parameters.js";
1313
import {
1414
createTranslationKeyPrompt,
15-
updateTranslationKeyPrompt,
1615
updateTranslationsBulkPrompt,
1716
getAllTranslationKeysPrompt,
1817
getTranslationKeyDetailsPrompt,
1918
getTagsPrompt,
2019
createTagPrompt,
2120
getLanguagesPrompt,
2221
getTranslationsPrompt,
22+
createLanguagePrompt,
2323
} from "./prompts.js";
2424

2525
export type Tool = {
@@ -37,17 +37,10 @@ export type Tool = {
3737

3838
const tools: Tool[] = [
3939
{
40-
method: "create_translation_key",
41-
name: "Create Translation Key",
40+
method: "create_translation_key_bulk",
41+
name: "Create Translation Key Bulk",
4242
description: createTranslationKeyPrompt,
43-
parameters: createTranslationKeyParameters,
44-
actions: { translationKeys: { write: true } },
45-
},
46-
{
47-
method: "update_translation_key",
48-
name: "Update Translation Key",
49-
description: updateTranslationKeyPrompt,
50-
parameters: updateTranslationKeyParameters,
43+
parameters: createTranslationKeyBulkParameters,
5144
actions: { translationKeys: { write: true } },
5245
},
5346
{
@@ -92,6 +85,13 @@ const tools: Tool[] = [
9285
parameters: getLanguagesParameters,
9386
actions: { languages: { read: true } },
9487
},
88+
{
89+
method: "create_language",
90+
name: "Create Language",
91+
description: createLanguagePrompt,
92+
parameters: createLanguageParameters,
93+
actions: { languages: { write: true } },
94+
},
9595
{
9696
method: "get_translations",
9797
name: "Get Translations",

0 commit comments

Comments
 (0)