@gluneau/hive-mcp-server
Version:
An MCP server that enables AI assistants to interact with the Hive blockchain
98 lines • 4.3 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPostContent = getPostContent;
exports.getPostsByTag = getPostsByTag;
exports.getPostsByUser = getPostsByUser;
// Content retrieval tools implementation
const client_1 = __importDefault(require("../config/client"));
const error_1 = require("../utils/error");
const response_1 = require("../utils/response");
// Get a specific post by author and permlink
function getPostContent(params) {
return __awaiter(this, void 0, void 0, function* () {
try {
const content = yield client_1.default.database.call('get_content', [
params.author,
params.permlink,
]);
if (!content.author) {
return (0, response_1.errorResponse)(`Error: Post not found: ${params.author}/${params.permlink}`);
}
return (0, response_1.successJson)({
title: content.title,
author: content.author,
body: content.body,
created: content.created,
last_update: content.last_update,
category: content.category,
tags: content.json_metadata ? JSON.parse(content.json_metadata).tags || [] : [],
url: `https://hive.blog/@${params.author}/${params.permlink}`,
});
}
catch (error) {
return (0, response_1.errorResponse)((0, error_1.handleError)(error, 'get_post_content'));
}
});
}
// Get posts by tag
function getPostsByTag(params) {
return __awaiter(this, void 0, void 0, function* () {
try {
const posts = yield client_1.default.database.getDiscussions(params.category, {
tag: params.tag,
limit: params.limit,
});
const formattedPosts = posts.map((post) => ({
title: post.title,
author: post.author,
permlink: post.permlink,
created: post.created,
votes: post.net_votes,
payout: post.pending_payout_value,
url: `https://hive.blog/@${post.author}/${post.permlink}`,
}));
return (0, response_1.successJson)(formattedPosts);
}
catch (error) {
return (0, response_1.errorResponse)((0, error_1.handleError)(error, 'get_posts_by_tag'));
}
});
}
// Get posts by user
function getPostsByUser(params) {
return __awaiter(this, void 0, void 0, function* () {
try {
// For blog and feed queries, the username is provided as the tag parameter
const posts = yield client_1.default.database.getDiscussions(params.category, {
tag: params.username,
limit: params.limit,
});
const formattedPosts = posts.map((post) => ({
title: post.title,
author: post.author,
permlink: post.permlink,
created: post.created,
votes: post.net_votes,
payout: post.pending_payout_value,
url: `https://hive.blog/@${post.author}/${post.permlink}`,
}));
return (0, response_1.successJson)(formattedPosts);
}
catch (error) {
return (0, response_1.errorResponse)((0, error_1.handleError)(error, 'get_posts_by_user'));
}
});
}
//# sourceMappingURL=content.js.map